python从入门到实践chapter07

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.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值