编程语言
首页 > 编程语言> > Python_01Day_练习

Python_01Day_练习

作者:互联网

基本程序设计

编写一个简单的程序

在Python里面不需要定义数据的类型

控制台的读取与输入

变量命名的规范

变量、赋值语句和赋值表达式

同时赋值

var1, var2,var3... = exp1,exp2,exp3...

 

定义常量

数值数据类型和运算符

运算符 /、//、**

运算符 %

EP:

科学计数法

计算表达式和运算优先级

增强型赋值运算

类型转换

EP:

Project

 

Homework

1

 

In [2]
celsius = float(input("Enter a degree in Celsius:"))
fahrenheit = (9 / 5) * celsius + 32
print('{} Celsius is {} Fashrenheit'.format(celsius,fahrenheit))
 
Enter a degree in Celsius:43
43.0 Celsius is 109.4 Fashrenheit
  In [1]:
import math 
radius = float(input('Enter the radius :'))
length = float(input('Enter the length :'))
area = radius * radius * math.pi
volume = area * length 
print('The area is:%.4f' % area)
print('The volume is:%.1f' % volume)

Enter the radius :5.5
Enter the length :12
The area is:95.0332
The volume is:1140.4
In [8]:
feet = float(input('Enter a value for feet :'))
meters =(305 / 1000) * feet
print('{} feet is {:.4f} meters:'.format(feet, meters))
 
Enter a value for feet :16.5
16.5 feet is 5.0325 meters:
  In [10]:
import math 
M = float(input('Enter the amount of in kilograms  :'))
initialTemperature = float(input('Enter the initial temperature :'))
finalTemperature = float(input('Enter the final temperature :'))
Q = M * (finalTemperature - initialTemperature) * 4184
print('The energy needed is:%.1f' % Q)
 
Enter the amount of in kilograms  :55.5
Enter the initial temperature :3.5
Enter the final temperature :10.5
The energy needed is:1625484.0
  In [1]:
import math 
balance,interstrate = map(float,input('Enter balance and interest rate (e.g., 3 for 3%):').split(','))
interest = balance * (interstrate / 1200)
print('The interest  is:%.5f' % interest)

Enter balance and interest rate (e.g., 3 for 3%):1000,3.5
The interest  is:2.91667
  In [2]:  
import math 
v0,v1,t = map(float,input('Enter v0, v1, and t:').split(','))
a = (v1 - v0 ) / t
print('The average acceleration  is:%.4f' % a) 
Enter v0, v1, and t:5.5,50.9,4.5
The average acceleration  is:10.0889
  In [11]:  
import math
A = float(input("Enter the monthly saving amount:"))
B=A * ( 1 + 0.00417)
C=(A + B) * ( 1 + 0.00417)
D=(A + C) * ( 1 + 0.00417)
E=(A + D) * ( 1 + 0.00417)
F=(A + E) * ( 1 + 0.00417)
G=(A + F) * ( 1 + 0.00417)
print('After the sixth month, the account value is :%.2f' %G) 


Enter the monthly saving amount:100
After the sixth month, the account value is :608.82
  In [6]:  
number = int(input("Enter a number between 0 and 1000:"))
a = number // 100
b = number // 10 % 10
c = number % 10
print('The sum of the digits is',a+b+c, end = ' ')
 
Enter a number between 0 and 1000:999
The sum of the digits is 27 




-------------------------------------------------------------------------------




计算器   

a = int (input('请输入一个数字 = '))
b = int (input ('请输入一个数字 = '))
print('%d + %d = %d' % (a,b, a + b))
print('%d - %d = %d' % (a,b, a - b))
print('%d * %d = %d' % (a,b, a * b))

 

判断 闰年 平年  

year = int(input( 'year:>>'))
if (year % 4 ==0 and year % 100 !=0) or (year % 400 == 0):
print('闰年')
else:
print('平年')

 

华氏转摄氏

F = float(input("输入华氏度:"))
C = (F-32) / 1.8
print('{} 华氏度 = {} 华氏度'.format(F,C))

 

正方形:

for i in range(10):
print('# ',end="")
print()
for k in range(8):
print('# ',' '*16,'#',sep="")
for j in range(10):
print('# ',end="")



标签:01Day,float,Python,练习,feet,radius,Enter,print,input
来源: https://www.cnblogs.com/HZDHH/p/11272983.html