Python初级编程问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 00:34:54
随机出一道10以内的加法问题,用户输入答案后若正确,显示well done,若错误显示not right。最后统计用户的做对多少道题。(一共10道题)请专家修改一下这段代码。
import random
def question():
a=random.randrange(1,11)
b=random.randrange(1,11)
print 'what is', a, 'add',b,'?'
c=a+b
anwser=int(raw_input('Type your anwser:'))
if anwser==c:
print 'Well done!'
return 1
else:
print 'Not right!'
return 0
n=0
right=0
while n<10:

print 'you got',right,'right questions.'

在百度空间写python代码——python是以缩进来表示代码块的……

下面的一个-代表一个空格
import random
def question():
--a=random.randrange(1,11)
--b=random.randrange(1,11)
--print 'what is', a, 'add',b,'?'
--c=a+b
--anwser=int(raw_input('Type your anwser:'))
--if anwser==c:
----print 'Well done!'
----return 1
--else:
----print 'Not right!'
----return 0

n=0
right=0
while n<10:
--right+=question()
--n=n+1
print 'you got',right,'right questions.'