Created
January 10, 2017 18:20
-
-
Save leonchen417/1c2a7f452e7e3e64bd9a661e8ae5846e to your computer and use it in GitHub Desktop.
ch4 code-structure created by leonchen417 - https://repl.it/FEWM/31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
# this capitalize input until q is pressed | |
while True: | |
stuff = input("String to capitalize [type q to exit]: ") | |
if stuff =="q": | |
break | |
print(stuff.capitalize()) | |
''' | |
''' | |
while True: | |
value = input("I square an odd number for you, otherwise I skip [type q to exit]:") | |
if value =='q': | |
break | |
number = int(value) | |
if number % 2 ==0: | |
continue #skip | |
print('the square of ', number, " is ", number**2) | |
''' | |
''' | |
numbers = [1,3,5] #try add 6 and run again | |
position = 0 | |
while position < len(numbers): | |
number = numbers[position] | |
if number %2 ==0: | |
print('Even number founded : ', number) | |
break | |
position+=1 | |
else: | |
print('no even number founded') | |
''' | |
numbers2 = [1,3,4,5,6] | |
for number in numbers2: | |
print(number) | |
print('---start2') | |
cheeses = [] | |
while len(cheeses)<10: | |
chees = input("I can save some cheeses for you, but I don't like American [type q to exit]:") | |
if chees =='q': | |
break | |
elif chees =="American": | |
continue #skip | |
cheeses.append(chees) | |
print('you kept the', chees, " in cheeses sotrage", cheeses) | |
else: | |
print('your storage of 10 runs out') | |
print('---start2') | |
index = len(numbers2) | |
for indx in range(index): | |
print(numbers2[indx]) | |
#understand how for loop interact with dictionary | |
accusation = {'room':'ballroom','weapon':'lead pipe','person':'Col. Mustard'} | |
for key,value in accusation.items(): #items return both keys and value | |
if key =='some conditions': | |
break | |
print('key',key,'has the content of',value) | |
else: | |
print('The for loop complete normally with no break') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment