我知道如何从用户那里获取一个输入python 2.5:
raw_input("enter 1st number")
Run Code Online (Sandbox Code Playgroud)
这将打开一个输入屏幕并输入第一个数字.如果我想要第二个输入,我需要重复相同的命令,并在另一个对话框中打开.如何在打开的同一个对话框中将两个或多个输入放在一起,以便:
Enter 1st number:................
enter second number:.............
Run Code Online (Sandbox Code Playgroud)
jcf*_*wer 15
这样的事怎么样?
user_input = raw_input("Enter three numbers separated by commas: ")
input_list = user_input.split(',')
numbers = [float(x.strip()) for x in input_list]
Run Code Online (Sandbox Code Playgroud)
(你可能也想要一些错误处理)
anu*_*619 15
这可能有用:
a,b=map(int,raw_input().split())
Run Code Online (Sandbox Code Playgroud)
然后,您可以单独使用"a"和"b".
Python 和所有其他命令式编程语言执行一个又一个命令。因此,你可以这样写:
first = raw_input('Enter 1st number: ')
second = raw_input('Enter second number: ')
Run Code Online (Sandbox Code Playgroud)
然后,您可以对变量first和进行操作second。例如,您可以将存储在其中的字符串转换为整数,然后将它们相乘:
product = int(first) * int(second)
print('The product of the two is ' + str(product))
Run Code Online (Sandbox Code Playgroud)