程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] learning notes week4-1 numerical calculation

編輯:Python

【PYTHON】 Time conversion output numerical calculation

Enter an integer in seconds , Convert to hours 、 Minute and second output . See the example for the output format .( With 24 The hour system shows )

Input

Enter an integer .

Output

Output hours : branch : second , There is a space between each part of the output

The sample input

11730

Sample output

3 : 15 : 30

a=eval(input())
h=a//3600
m=a//60%60
s=a%60
print("{} : {} : {}".format(h,m,s))

【PYTHON】 Find the area and perimeter of the triangle # Numerical calculation

Title Description

Enter the three sides of the triangle a、b、c, Calculate and output area and perimeter . Suppose that the three sides of the input triangle are legal shaping data . Triangle area formula : 

 , among s=(a+b+c)/2.

Input

Enter one data per line , Represents one side of a triangle .

Output

area= area ;perimeter= Perimeter , Area and perimeter retention 2 Decimal place

The sample input

3 4 5

Sample output

area=6.00;perimeter=12.00

Tips

import math # Import math library math.sqrt(x) # call sqrt Function to realize the square operation ,x Data representing the required value

a=eval(input())
b=eval(input())
c=eval(input())
s=(a+b+c)/2
area=(s*(s-a)*(s-b)*(s-c))**0.5
perimeter=a+b+c
print("area={:.2f};perimeter={:.2f}".format(area,perimeter))

PYTHON】 A plan to give customers change # Numerical calculation

Title Description

The store needs change for its customers , Now there are enough sheets , The face values are 50 element 5 Genna 1 element . Enter an integer amount value to give the change scheme , Suppose there is enough RMB , And give priority to coins with large denominations .

Input

Enter... In the first line 1 No more than 1000 The positive integer .

Output

Output the required values for various denominations .

The sample input

283

Sample output

50 Number of sheets required for yuan denomination :5 5 Number of sheets required for yuan denomination :6 1 Number of sheets required for yuan denomination :3

a=eval(input())
b=a//50
c=a%50//5
d=a%5
print("50 Number of sheets required for yuan denomination :{}".format(b))
print("5 Number of sheets required for yuan denomination :{}".format(c))
print("1 Number of sheets required for yuan denomination :{}".format(d))

【PYTHON】 Calculate interest rates # Numerical calculation

Title Description

Calculate deposit interest , The formula is interest=money×(1+rate)^year−money, interest Is the interest on the deposit when it matures ( pre-tax ),money Is the deposit amount ,year It's the shelf life ,rate It's the annual interest rate .

Input

Input 3 Data , Whitespace separated . The first data represents money, The second data represents year, The third data represents rate

Output

1000 3 0.025

The sample input

76.89

a,b,c=map(eval,input().split(" "))
interest=a*(1+c)**b-a
print("{:.2f}".format(interest))

【PYTHON】M And N Mathematical operation of # Numerical calculation

Title Description

The user enters two numbers M and N, among N Is an integer , Calculation M and N Of 5 The result of a mathematical operation , And output in turn , The results are separated by spaces .‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

5 The two mathematical operations are :‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

   M And N And 、M And N The product of the 、M Of N The next power 、M except N The remainder of 、M and N The greater of

Input

10, 2

Output

12 20 100 0 10

The sample input

10, 2

Sample output

12 20 100 0 10

a,b=map(eval,input().split(","))
print("{} {} {} {} {}".format((a+b),(a*b),(a**b),(a%b),(max(a,b))))

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved