- 论坛徽章:
- 0
|
菜鸟上路,
求教:
#!/usr/bin/python
#Filename:first.py
print 'this is my first program ,please gei me some congralations ,thank you !!!'
print 'now ,i want to gei you a question ,please gei me an answer .'
for i in range(1,8,1):
print 'this is ',i,'line'
for r in range(1,i,1):
print r
print 'it is over '
像上面的程序,我想要的效果是
1
12
123
1234
12345
123456
1234567
12345678
可是为什么总是不行呢?上面的执行结果是
#!/usr/bin/python
this is my first program ,please gei me some congralations ,thank you !!!
now ,i want to gei you a question ,please gei me an answer .
this is 1 line
this is 2 line
1
this is 3 line
1
2
this is 4 line
1
2
3
this is 5 line
1
2
3
4
this is 6 line
1
2
3
4
5
this is 7 line
1
2
3
4
5
6
it is over
请问为什么总是少一行呢 ?为甚8那行总是没有呢?第一二行怎们那样呢?
还有就是怎么不让它换行啊,
我采学两三天,别怪我太笨哦
还有就是这个哦
#!C:\Python24\python.exe
#Filename:l.py
number=23
value=1
while value:
try:
guess=int(raw_input('Enter an interger :'))
except ValueError:
print 'sorry ,please input a new number ,thank you .'
continue
else:
value=0
if guess==number:
print 'Congratulation to you ,you guessed it ,you are very good .'
print '(but you do not win any prizes !)'
elif guess<number:
print 'No ,sorry ,it is a little lower than that .'
else:
print 'No ,sorry ,it is a little highter than that '
print 'done'
print ' '
print ' '
print ' '
就是对数据的输入错误处理,而要求必须输入整数的时候,我那样处理是不是太麻烦了啊?
谢谢了,谢谢了哦,想不出什么别的方法了啊 |
|