7-3
number = input()
if int(number) % 10 == 0:
print("yes")
else:
print("no")
输出结果:
10
yes
15
no
7-5
while True:
age = input("How old are you?(input quit to quit)\n")
if age == "quit":
exit()
elif int(age) < 3:
print("you are free.")
elif int(age) >= 3 and int(age) <= 12:
print("you have to pay 10 dollars.")
else:
print("you have to pay 15 dollars.")
输出结果:
How old are you?(input quit to quit)
2
you are free.
How old are you?(input quit to quit)
10
you have to pay 10 dollars.
How old are you?(input quit to quit)
15
you have to pay 15 dollars.
How old are you?(input quit to quit)
12
you have to pay 10 dollars.
How old are you?(input quit to quit)
quit
7-6.1
age = input("How old are you?(input quit to quit)\n")
while age != "quit":
if int(age) < 3:
print("you are free.")
elif int(age) >= 3 and int(age) <= 12:
print("you have to pay 10 dollars.")
else:
print("you have to pay 15 dollars.")
age = input("How old are you?(input quit to quit)\n")
7-6.2
active = True
while active:
age = input("How old are you?(input quit to quit)\n")
if age == "quit":
active = False
elif int(age) < 3:
print("you are free.")
elif int(age) >= 3 and int(age) <= 12:
print("you have to pay 10 dollars.")
else:
print("you have to pay 15 dollars.")
7-6.3
active = True
while active:
age = input("How old are you?(input quit to quit)\n")
if age == "quit":
break
elif int(age) < 3:
print("you are free.")
elif int(age) >= 3 and int(age) <= 12:
print("you have to pay 10 dollars.")
else:
print("you have to pay 15 dollars.")
输出结果:同7-5
7-10
name = ""
place = ""
active = True
places = {}
while active:
name = input("What is your name? ")
place = input("If you could visit one place in the world,where would you go? ")
flag = input("Would you like to let another person respond(yes or no)? ")
while True:
if flag == "no":
active = False
break
elif flag != "yes":
flag = input("Please enter yes or no? ")
else:
break
places[name] = place
for key,value in places.items():
print(key + " would like to go to " + value + ".")
输出结果:
What is your name? Eric
If you could visit one place in the world,where would you go? London
Would you like to let another person respond(yes or no)? yes
What is your name? Kangkang
If you could visit one place in the world,where would you go? Sichuan
Would you like to let another person respond(yes or no)? yes
What is your name? Luffy
If you could visit one place in the world,where would you go? Tokyo
Would you like to let another person respond(yes or no)? no
Luffy would like to go to Tokyo.
Kangkang would like to go to Sichuan.
Eric would like to go to London.