||
input () ——提示输入,输入对象为string格式,返回值为string格式。
python脚本示例如下:
#!/usr/bin/python3 (注:#!后面的路径可通过在terminal中输入which python确定)
myname = input ('What is your name?')
print ('Hello ' + myname)
print (myname + ', Let's add two numbers')
a = input ('Enter the first number: ') # a 是string格式
b = input ('Enter the second number: ') # b 是string格式
cc = a + b
print (cc)
print ('The sum of a and b is ' + cc)
c = int(a) + int (b) # int () 将对象转化成整数格式
print (repr(c))
print ('The sum of a and b is ' + repr (c))
运行结果如下:
What is your name? (提示输入)YY
Hello YY
YY, Let's add two numbers
Enter the fitst number: (提示输入)2.3
Enter the fitst number: (提示输入)2
'2.32'
The sum of a and b is 2.32
'4'
The sum of a and b is 4
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-23 21:18
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社