Python(一)初学小实验
来源:互联网 发布:mac os 最好的版本 编辑:程序博客网 时间:2024/05/22 14:27
实验
__author__ = 'Frank'
temp = input("input number:")
guess = int(temp)
if guess == 8:
print("Right is 8")
print("yea,very good,you won!")
else:
print("Unfortunate,you are wrong!")
print("Right is 8")
print("Game Over!!!")
------------------------------------------------------------------------------
实验二:
__author__ = 'Frank'
first = "3"
second = "4"
third = first + second
print(third) #这里的输出结果是34,也就是3和4并列出来的数字,并不是真正的数字“34”
first = 3
second = 4
third = first + second
print(third) #这里输入的结果是7,也就是3+4=7的意思,区别于上面的部分。
----------------------------------------------------------------------------
综上所述:print输出常量后面的括号内如果加“”号,
则表示输入双引号内的实际数值,而如果不加双引号(),则括号内的是一个变量。
也就是输出变量的值。
------------------------------------------------------------------------------------------------------------------------
实验三:
__author__ = 'Frank'
print('''line1\nline3''') #这里的\n表示换行
print('temp')
print("c:\\i'am tao") #这是print("")的直接输出内容
print('c:\\i\'am tao') #这里是print('')的单引号,内部需要使用到转义字符,反斜杠\
print("hello\n" * 3) #连续输出3次,没输出一次就换行
那么实验二的结果就是:
line1
line3
temp
c:\i'am tao
c:\i'am tao
hello
hello
hello
----------------------------------------------------------------------------------------------------------------
实验四:
__author__ = 'Frank'
import random
secret = random.randint(1,10)
temp = input("please give me anumber...\n")
guess = int(temp)
count = 0
while guess != secret:
if count== 0 and guess > secret:
print("it's too big!")
if count== 0 and guess < secret:
print("it's too small!")
temp =input("please give me a number again...\n")
guess =int(temp)
count +=1
if count> 2:
print("because you are wrong by four,so break. ")
break
if guess== secret:
print("yes,you are right!")
print("haha~~~")
else:
ifguess > secret:
print("it's very big!")
else:
print("it's very small!")
print("Game Over!!!")
#第2行是调用random的随机函数库
#第3行是指定random的随机函数库的取值的范围randint(1,10)
#第6行的count = 0是指的计数,也就是输入数字的次数。而相对的第14行的conut += 1的意思是count= conut + 1,
#即每输入一次count的值就会+1
--------------------------------------------------------------------------------------------------------------------------------
- Python(一)初学小实验
- python 初学一问题
- Python初学(一)
- 初学Python(一)
- 初学Python(一)
- Python初学一
- Python初学(一)
- python初学基础知识一
- 初学Python(一)
- 初学python(一)
- Python初学小知识汇总
- 初学python的小知识
- 初学python,爬虫小项目
- 初学Python笔记(一)
- Python初学(一)DocString
- Python初学笔记(一)
- 初学python一:零碎知识点
- python初学零碎记一
- c标签 数据库内容放到页面显示 防止alert弹出 作为普通内容展示
- Systemd 与 Systemctl 命令指南
- (七)zookeeper 管理配置节点
- Java工程师的一道面向对象面试题
- 资源更新管理
- Python(一)初学小实验
- hadoop完全分布式集群搭建
- C#Winform上显示实时时间
- javascript垃圾回收和内存泄漏
- GridBagConstraints(网格组布局管理器的使用)
- 高性能Tomcat:漫谈行走在sendfile之上的Tomcat
- Java基础:JVM运行机制
- React Native -- StyleSheet
- PHP文件读写操作