[英]How do i make my program ask further questions to the user?
i am literally an absolute beginner in programming so i would be very grateful if someone could help me out.我实际上是编程方面的绝对初学者,所以如果有人能帮助我,我将非常感激。 my program looks like this:
我的程序如下所示:
age = input("Your Age:")
ageNum = int(age)
if ageNum >= 18:
print("Why do you want to ride the roller coaster")
else:
print("You are not allowed to ride the roller coaster")
it functions exactly the way i want it to but i want add a feature.i want it to ask allow the user to answer 'why do you want to ride the roller coaster'.它完全按照我想要的方式运行,但我想添加一个功能。我希望它询问允许用户回答“你为什么要乘坐过山车”。
To ask a question for the user to answer, instead of saying问一个问题让用户回答,而不是说
print("Why do you want to ride the roller coaster")
(which just displays something on the screen rather than asking the user a question) you can use the built-in input()
function. (它只是在屏幕上显示一些东西而不是问用户一个问题)你可以使用内置的
input()
function。 So you can replace the line that has所以你可以替换有
print("Why do you want to ride the roller coaster")
with和
yourVariableName = input("Why do you want to ride the roller coaster? ")
Then you can respond to the user's answer:然后你可以回复用户的回答:
print("Your message here")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.