我要执行此操作:
从STDIN读取两个整数并在其中打印三行:
第一行包含两个数字的总和。 第二行包含两个数字的差(第一-第二)。 第三行包含两个数字的乘积。
有人可以帮我吗?
答案 0 :(得分:0)
慢慢开始并分解
# Get your data from the user, use input
num_one = input("Please enter the first number: ")
num_two = input("Please enter the second number: ")
# Create the sum, diff, and product, casting as integer
sum = int(num_one) + int(num_two)
diff = int(num_one) - int(num_two)
product = int(num_one) * int(num_two)
# Print each output casting as a string since we can't concatenate a string to an integer
print("The sum is: "+str(sum))
print("The difference is: "+str(diff))
print("The product is: "+str(product))
现在,您还应该在此处进行一些错误检查,以防用户不输入任何内容:
# Get your data from the user, use input
num_one = input("Please enter the first number: ")
num_two = input("Please enter the second number: ")
if(num_one == "" or num_two == ""):
print("You did not enter enter two numbers. Exiting...")
exit
else:
# Create the sum, diff, and product, casting as integer
sum = int(num_one) + int(num_two)
diff = int(num_one) - int(num_two)
product = int(num_one) * int(num_two)
# Print each output casting as a string since we can't concatenate a
string to an integer
print("The sum is: "+str(sum))
print("The difference is: "+str(diff))
print("The product is: "+str(product))
答案 1 :(得分:0)
raw_input读取输入,int将字符串转换为整数,print
打印输出
a = int(raw_input("numebr 1: "))
b = int(raw_input("numebr 2: "))
print a + b
print a - b
print a * b
input读取输入,int将字符串转换为整数,将输出打印到print,
a = int(input("numebr 1: "))
b = int(input("numebr 2: "))
print (a + b)
print (a - b)
print (a * b)
答案 2 :(得分:-1)
return (
Object.entries(props.values).map(([key, value], index) => (
<div key={keys[index].span} >
<span/>
<p key={keys[index].p} />
</div>
))
);