Python if and input
2010-12-29 01:54
387 查看
input用于输入流的捕捉:
执行结果:
Enter an integer: 20
No, it is a little higher than that
Enter an integer: 30
No, it is a little lower than that
Enter an integer: 23
Congratulations, you guessed it.
(but you do not win any prizes!)
The while loop is over.
Done
#!/usr/bin/python # Filename: if.py number = 23 guess = int(raw_input('Enter an integer : ')) if guess == number: print 'Congratulations, you guessed it.' # New block starts 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' # This last statement is always executed, after the if statement is executed
执行结果:
Enter an integer: 20
No, it is a little higher than that
Enter an integer: 30
No, it is a little lower than that
Enter an integer: 23
Congratulations, you guessed it.
(but you do not win any prizes!)
The while loop is over.
Done
相关文章推荐
- [python3教程]第七章.输入输出(Input and Output)
- python学习笔记 loop&&raw_input 7&& if
- python input and raw_input
- python tutorial 学习笔记(四) Input and Output, 字符串的转换等
- Python Intro - System Input and Output
- Python学习笔记(7)Mouse Input, More Lists and Dictionaries
- 【再回首Python之美】【and-or】危险的and-or,安全的if-else,和安全的and-or
- The Python Tutorial 7——Input and Output
- python-Input and Output--已阅
- Python 三元条件判断表达式(and or/if else)
- Shell Script Examples: case, count, for, if, while and User input
- [python3教程]第十四章.交互输入编辑和历史替代(Interactive Input Editing and History Substitution)
- python input and output and cpickle
- The Python Tutorial - Input and Output
- Python input and output
- python练习-if-else-and
- python input and while循环
- python - Prompt the user to input something else if the first input is invalid - Stack Overflow
- Python 3.3 Tutorial Notes - 5:Input and Output
- python中if __name__ == '__main__': 的解析