pi =3.14
r = float(input("请输入半径 :"))
area = pi*r**2
print(area)
pi =3.14
#r = float(input("请输入半径 :"))
#area = pi*r**2
#print(area)
#,会输出一个空格
#print ("The area of circe is :",area)
#print("efwe
eger")
age=20
gender = "woman"
if age>=18 and gender == "woman":#age 前一定要有空格
#if gender =="man":也可以写两个if
print("恭喜你,你成年了!")#print前一定要有空格,一定比最近的if 还要缩进
else:
print("加油长大,小屁孩!")
1 #input 是字符串型的
2 num=input("请输入一个数字: ")
3 #格式转化
4 num=eval(num)
5 print(100+num)
6
7
8 请输入一个数字: 20
9 120
10
11
12
13 #计算圆的面积和周长
14 pi=3.14
15 r=input("请输入圆的半径:")
16 r=eval(r)
17 s=pi*r*r
18 c=2*pi*r
19 print("半径为{}的圆的面积为{},周长为{}。 ".format(r,s,c))
20
21
22
23 请输入圆的半径:8
24 200.96
25 50.24
1 name = "Alice"
2 age=10
3 #{1}对应format的第二个
4 output = "I am {1} and I am {0} years old .".format(age,name)
5 print(output)
6
7 I am Alice and I am 10 years old .
8
9 #<左对齐,^居中>右对齐
10 output = "{0:<10},{1:^10},{2:>10}".format("Tom","and","Jerry")
11 print(output)
12
13 Tom , and , Jerry
14
15
16 pi=3.1415926
17 print("Pi={0:.3f}".format(pi))
18
19 Pi=3.142
20 >>>
21
22
23 name=input("请输入您的姓名: ")
24 print("您好, "+name)
25
26 === RESTART: C:/Users/陈良/AppData/Local/Programs/Python/Python37/ninhao.py ===
27 请输入您的姓名: 陈良
28 您好, 陈良
29 >>>
30
31
32
33 F=input("请输入需要转化的华氏温度: ")
34 F=eval(F)
35 C=5/9*(F-32)
36 #默认{}按从小到大的顺序
37 print("华氏温度{}对应的摄氏温度是{:.1f}".format(F,C))
38
39 请输入需要转化的华氏温度: 100
40 华氏温度100对应的摄氏温度是37.8
41 >>>
# if else
score = int(input("请输入分数 :"))
if score >=90:
print('A')#必须加()
elif score >=80:
print("B")
elif score >=70:
print("C")
elif score >=60:
print("E")
else :
print("F")
1 import math
2 a = float(input("a: "))
3 b = float(input("b: "))
4 c = float(input("c: "))
5 if a!=0:
6 d = b**2-4*a*c
7 if d<0:
8 print ("no solution!")
9 elif d==0:
10 s = -b/(2*a)
11 print("s: ",s)
12 else:
13 r = math.sqrt(d)
14 s1 = (-b+r)/(2*a)
15 s2 = (-b-r)/(2*a)
16 print ("Two distinct solutions are : ",s1,s2)
17
1 adpoints = float(input("领先的分数为 :"))
2 remaintime = float(input("当前比赛剩余的时间: "))
3 kongqiu = input("目前领先对是否控球 :(yes/no)")
4 adpoints-=3
5 if kongqiu == "yes":
6 adpoints+=0.5
7 else:
8 adpoints-=0.5
9 adpoint**=2
10 if adpoints>remaintime:
11 print("safe")
12 else:
13 print("unsafe")
14
15
1 adpoints = float(input("领先的分数为 :"))
2 remaintime = float(input("当前比赛剩余的时间: "))
3 kongqiu = input("目前领先对是否控球 :(yes/no)")
4 adpoints-=3
5 print(adpoints)#前面不能有空格
6 if kongqiu == "yes":#注意大小写
7 adpoints+=0.5
8 else:
9 adpoints-=0.5
10 if adpoints <0:
11 adpoints = 0
12 adpoints **= 2#前面不能有空格
13 if adpoints>remaintime:#前面不能有空格
14 print("safe")
15 else:
16 print("unsafe")
17
18