prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
active = True
while active:
message = input(prompt)
if message == 'quit':
active = False
else:
print(message)
Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. 4545
4545
Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. quit
prompt = "If you tell us who you are, we can personalize the messages you see."
prompt += "\nWhat is your first name? "
name = input(prompt)
print("\nHello, " + name + "!")
If you tell us who you are, we can personalize the messages you see.
What is your first name? zou
Hello, zou!
height = input("How tall are you, in inches? ")
height = int(height)
if height >= 36:
print("\nYou're tall enough to ride!")
else:
print("\nYou'll be able to ride when you're a little older.")
print('++++++++++++++++++++++++++++++++++++++++')
height = input("How tall are you, in inches? ")
if height >= 36:
print("\nYou're tall enough to ride!")
else:
print("\nYou'll be able to ride when you're a little older.")
How tall are you, in inches? 22
You'll be able to ride when you're a little older.
++++++++++++++++++++++++++++++++++++++++
How tall are you, in inches? 22
TypeError: '>=' not supported between instances of 'str' and 'int'
number = input("Enter a number, and I'll tell you if it's even or odd: ")
number = int(number)
if number % 2 == 0:
print("\nThe number " + str(number) + " is even.")
else:
print("\nThe number " + str(number) + " is odd.")
Enter a number, and I'll tell you if it's even or odd: 14
The number 14 is even.
current_number = 1
while current_number <= 5:
print(current_number)
current_number += 1
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
message = ""
while message != 'quit':
message = input(prompt)
if message != 'quit':
print(message)
1
2
3
4
5
Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. godie
Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. quit
responses = {}
# Set a flag to indicate that polling is active.
polling_active = True
while polling_active:
# Prompt for the person's name and response.
name = input("\nWhat is your name? ")
response = input("Which mountain would you like to climb someday? ")
# Store the response in the dictionary:
responses[name] = response
# Find out if anyone else is going to take the poll.
repeat = input("Would you like to let another person respond? (yes/ no) ")
if repeat == 'no':
polling_active = False
# Polling is complete. Show the results.
print("\n--- Poll Results ---")
for name, response in responses.items():
print(name + " would like to climb " + response + ".")
What is your name? zou
Which mountain would you like to climb someday? XX shang
Would you like to let another person respond? (yes/ no) yes
What is your name? qiu
Which mountain would you like to climb someday? YY hill
Would you like to let another person respond? (yes/ no) no
--- Poll Results ---
zou would like to climb XX shang.
qiu would like to climb YY hill.