问题描述
我还是编程新手。 我想编写一个完整的脚本,在这里我可以由操作员决定并获得2个随机数,依此类推。 它起作用了,但是如果我想提供一些东西,则需要进行一些计算,例如59:6 =,并用逗号后的9位数字表示。 我确实以除法部分的代码结束了
def division():
x = randint(1,100)
y = randint(1,10)
a = int(input("Task: What is " + str(x) + ":" + str(y) + "?\n"))
b = x / y
g = round(b,0)
if a == g:
print("Nice!")
start()
else:
print("Wrong! The right answer is " + str(g))
start()
这不是我所知道的最好的解决方案,但是我只想进行计算而没有任何余数,但是我不知道怎么做。 有提示吗?
我的整个代码,如果您想测试的话:
from random import randint
def plus():
x = randint(1,1000)
y = randint(1,1000)
a = int(input("Task: What is " + str(x) + "+" + str(y) + "?\n"))
b = x + y
if a == x+y:
print("Nice!")
start()
else:
print("Wrong! The right answer is " + str(b))
start()
def minus():
x = randint(1,100)
if x < y:
minus()
else:
print()
a = int(input("Task: What is " + str(x) + "-" + str(y) + "?\n"))
b = x - y
if a == x-y:
print("Nice!")
start()
else:
print("Wrong! The right answer is " + str(b))
start()
def multiplication():
x = randint(1,10)
y = randint(1,10)
a = int(input("Task: What is " + str(x) + "*" + str(y) + "?\n"))
b = x * y
if a == x*y:
print("Nice!")
start()
else:
print("Wrong! The right answer is " + str(b))
start()
def division():
x = randint(1,0)
if a == g:
print("Nice!")
start()
else:
print("Wrong! The right answer is " + str(g))
start()
def start():
v = input("Which operator do you wanna use? (+,-,*,:): ")
if v == '+':
plus()
elif v == '-':
minus()
elif v == '*':
multiplication()
elif v == ':':
division()
else:
print(">>> End . . .")
start()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)