python3 basis of the "little exercise (1)."


(A) print three different characters
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)

(B) programming: variable is less than 10, a message is printed, greater than 10, a different message printed
1 # a=int(input("plase enter a number :"))
2 #
3 # if a<10 :
4 #     print("a<10")
5 # else:
6 #     print('a>10')

 

(C) programming: if less than 10, a message is printed; 10 greater than or equal to 25, print a different message; greater than 25, a different print another message.
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')

 

(Iv) the preparation of a division of two variables, and print the remainder
1 # a=int(input("please enter a number:"))
2 # b=int(input("plase enter a number:"))
3 # print(a%b)

 

(E) the preparation of a division of two variables, and print's program
1 # a=int(input("please enter a number:"))
2 # b=int(input("plase enter a number:"))
3 # print(a/b)

 

(F) programming: age imparting a variable integer value, depending on the values ​​of the print different string description
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!")

 

(Vii) write a function that takes the output and returns the digital square
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)

 

(H) function to write a string as a parameter and print
1 # def even_odd(2):
2 #     if x%2==0:
3 #         print("a")
4 #     alse:
5 #         print("b")
6 # print(even_odd())

 

(Ix) to prepare to accept the three required arguments, two optional parameters of the function.
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)

(J) Write a program with two functions. The first function should be accepted as an integer parameter and returns the integer ...
divided by 2. The second function should be accepted as a parameter an integer, and returns the integer value is multiplied by 4. ... The first call
a function, save the result to the variable and the second variable is passed to the function as an argument

Guess you like

Origin www.cnblogs.com/wangwenchao/p/11317709.html