简体   繁体   English

我如何让我的程序向用户提出更多问题?

[英]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.

相关问题 我如何制作一个while循环来询问用户是否要重新启动程序 - How do I make a while loop to ask the user if they want to restart the program 如何让程序询问用户输入的数量,并将他们输入的结果加在一起? - How do I make a program ask the user for the number of inputs, and add the result of their inputs togther? 如何在python中提出多个问题? - How do I ask multiple questions in python? 如果用户在我的 if 语句后回答“否”,我如何才能让代码再次询问您的姓名? - How do I make it so that the code will ask you your name again if the user answers no after my if statement? 如何让我的决策树模型在每个节点提问 - How to make my decision tree model ask questions at every node 在绘制线性方程时,如何让我的程序询问用户输入 - How to make my program ask for user input when graphing linear equations 如何在 if 语句中向用户提出多个问题? - How to ask a user multiple questions in if statements? 我如何要求用户输入时间 - How do I ask the user to input time Python-如何让我的程序反复要求输入,但仍存储其他输入? - Python - How do I get my program to ask for an input repeatedly but still store the other inputs? 如何制作程序,以便用户可以指定文件名? - How do I make my program so that the user can specify a file name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM