首页 > 编程语言 > 详细

python3基础之“小练习(1)”

时间:2019-08-07 21:19:47      阅读:238      评论:0      收藏:0      [点我收藏+]

(一)打印3个不同的字符
1 # a=int("123")
2 # b="123"
3 # c=1.2
4 # print(type(a),a)
5 # print(type(b),b)
6 # print(type(c),c)

(二)编写程序:变量小于10,打印一条消息,大于10,打印不同消息
1 # a=int(input("plase enter a number :"))
2 #
3 # if a<10 :
4 #     print("a<10")
5 # else:
6 #     print(‘a>10‘)

 

(三)编写程序:如果小于10,打印一条消息;大于10或等于25,打印一条不同的消息;大于25,打印另一条不同的消息。
1 # a=int(input("please enter a number:"))
2 #
3 # if a<10:
4 #     print("a<10")
5 # elif a>10 and  a<=25:
6 #     print("a<25")
7 # else:
8 #     print(‘a>25‘)

 

(四)编写一个将两个变量相除,并打印余数
1 # a=int(input("please enter a number:"))
2 # b=int(input("plase enter a number:"))
3 # print(a%b)

 

(五)编写一个将两个变量相除,并打印商的程序
1 # a=int(input("please enter a number:"))
2 # b=int(input("plase enter a number:"))
3 # print(a/b)

 

(六)编写程序:为变量age赋予一个整数值,根据不同的值打印不同的字符串说明
1 # age=int(input("please enter a number:"))
2 # if age<18:
3 #     print("you are so young!")
4 # elif age>18 and age<30:
5 #     print("you are old")
6 # else:
7 #     print("you are so old!")

 

(七)编写一个函数,接受输出,并返回该数字的平方
1 # x=int(input("enter a number:"))
2 # def f(x):
3 #     """
4 #     返回x**2的值
5 #     :param x:int
6 #     """
7 #     return x**2
8 # a=f(x)
9 # print(a)

 

(八)编写以字符串为参数并将其打印的函数
1 # def even_odd(2):
2 #     if x%2==0:
3 #         print("a")
4 #     alse:
5 #         print("b")
6 # print(even_odd())

 

(九)编写接受3个必选参数,两个可选参数的函数。
1 # x=int(input("enter a number"))
2 # y=int(input("enter a number:"))
3 # z=int(input("enter a number:"))
4 #
5 # def d(x,y,z,s=1,w=2):
6 #     return x+y+z-s-w
7 # a=d(x,y,z,s=1,w=2)
8 # print(a)

(十)编写一个带两个函数的程序。第一个函数应接受一个整数为参数,并返回该整数...
除以2 的值。第二个函数应接受一个整数作为参数,并返回该整数乘以4 的值。调用第...
一个函数,将结果保存至变量,并将变量作为参数传递给第二个函数

python3基础之“小练习(1)”

原文:https://www.cnblogs.com/wangwenchao/p/11317709.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!