我正在做我的第一个编程课程而且我已经被卡住了。
我正在尝试制作一个程序,告诉你,鉴于用户拥有多少件,你可以制作多少玩具。
要制作玩具,您需要有5个上部和2个下部。
我已将上面的部分分配给字母“a”,将下部分成字母“b”
这就是我目前所做的
print "Welcome to Amanda's Toy Factory"
print "At this factory, you will need to have 5 upper pieces and 2 lower pieces to create a toy"
x = input("How many toys would you like to make?")
print "To create",x,"toys, you will need", x*5, "upper pieces and", x*2, "lower pieces"
a = input("How many upper pieces did you bring?")
b = input("How many lower pieces did you bring?")
所以例如,如果你输入你有7个上部和5个下部,它应该告诉你你可以创造1个玩具,你将剩下2个上部和3个下部。
答案 0 :(得分:-1)
u, l = input('upper? '), input('lower? ')
nToys = min( int(u)/5, int(l)/2 )
upperLeft = u - nToys*5
lowerLeft = l - nToys*2
答案 1 :(得分:-3)
okey dokey。因为你使用打印的方式,我认为你使用旧版本的python。以下是我的表现:
a = input()
b= input("How many lower pieces did you bring?")
upper_left_over = a % 5
lower_left_over = b % 2
upper = int(int(a)/5)
lower = int(int(b)/2)
if upper > lower:
toys = lower
print("You can create", str(toys), "toys")
else:
toys = upper
print("You can create", str(toys), "toys")
print(upper_left_over, lower_left_over)
这显然是凌乱的。你可以清理它。希望这有帮助!