- 論壇徽章:
- 0
|
第一個(gè): if 語(yǔ)句,完全按照書上的書寫
#!/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')
執(zhí)行后報(bào)錯(cuò):
root@ubuntu:~$ python if
File "if", line 9
print('(but you do not win any prizes!)') # New block ends here
^
IndentationError: unexpected indent
第二個(gè): while語(yǔ)句
#!/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')
執(zhí)行后報(bào)錯(cuò):
root@ubuntu:~$ python while
File "while", line 8
guess = int(input("Enter a integer: '))
^
SyntaxError: EOL while scanning string literal
請(qǐng)各位高人指點(diǎn)。 多謝! |
|