- 论坛徽章:
- 0
|
第一个: if 语句,完全按照书上的书写
#!/usr/bin/python
# Filename: if.py
number = 23
guess = int(input('Enter an integer : '))
if guess == number:
print('Congratulations, you guessed it.') # New block statrs here
print('(but you do not win any prizes!)') # New block ends here
elif guess < number:
print('No, it is a little higher than that') # Another block
# You can do whatever you want in a block ...
else:
print('No, it is a little lower than that')
# You must have guess > number to reach here
print('Done')
执行后报错:
root@ubuntu:~$ python if
File "if", line 9
print('(but you do not win any prizes!)') # New block ends here
^
IndentationError: unexpected indent
第二个: while语句
#!/usr/bin/python
# Filename while.py
number == 23
running = Ture
while running:
guess = int(input("Enter a integer: '))
if guess == number:
print('Congratulations, you guessed it.')
running = False #thi cause the wile loop to stop
elif guess < number:
print('No, it is a little higher than that.')
else:
print('The while loop is over.')
# Do anything else you want to do here
print('Done')
执行后报错:
root@ubuntu:~$ python while
File "while", line 8
guess = int(input("Enter a integer: '))
^
SyntaxError: EOL while scanning string literal
请各位高人指点。 多谢! |
|