英俊男孩建坤 发表于 2020-9-22 00:34:40

求大佬帮我看看这个Python程序问题出在哪里!!!

帮我看看这个Python程序哪里有问题

number = eval(input ("Randomly enter a four-digit number"))
a = print(number//1000)
b = print((number-a*1000)//100)
c = print((number-a*1000-b*100)//10)
d = print((number-a*1000-b*100-c*10))
sum = a+b+c+dprint (sum)



就是运行不了 我实在觉得没有问题了QAQ

感激不尽!!!

疾风怪盗 发表于 2020-9-22 00:58:46

1、使用了中文状态的括号,要用英文的
2、print()单独使用,怎么能赋值呢?
3、最后一句怎么sum计算和print()放在一行了

number = eval(input("Randomly enter a four-digit number"))
a = number // 1000
print(a)
b = (number - a * 1000) // 100
print(b)
c = (number - a * 1000 - b * 100) // 10
print(c)
d = (number - a * 1000 - b * 100 - c * 10)
print(d)
sum = a + b + c + d
print(sum)

Datura 发表于 2020-9-22 01:08:28

number = eval(input ("Randomly enter a four-digit number")) #这行代码括号写成中文的了
a = number//1000
b = (number-a*1000)//100
c = (number-a*1000-b*100)//10
d = (number-a*1000-b*100-c*10)


print("a = %d\nb = %d\nc = %d\nd = %d\n" %(a, b, c, d))
sum = a+b+c+d
print (sum)
页: [1]
查看完整版本: 求大佬帮我看看这个Python程序问题出在哪里!!!