Operators and Expressions:Data Processing and Visulisation with Python (Python Exercise 2)

Data Processing and Visulisation with Python

Area of a circle

Write a Python program which accepts the radius of a circle from the user and compute the area.
(You may use pi from math module.)

from math import *
radius=input("Input the radius of the circle")
print("Input the radius of the circle : ",radius)
print("The area of the circle with radius ",str(radius),"is: ",(pi*(float(radius)**2)))

在这里插入图片描述

Name in reverse order

Write a Python program which accepts the user’s first and last name and print them in reverse order with a space between them.
Use your own names to replace mine in output

first_name=input("Input your First Name :")
print("Input your First Name :",first_name)
last_name=input("Input your Last Name :")
print("Input your Last Name :",last_name)
print("Hello "+ last_name + " " +first_name )

Sum of n+nn+nnn

Write a Python program that accepts a digit (n) and computes the value of n+nn+nnn.

n=input("Please input a digit:")
print( n + "+" + n*2 + "+" + n*3 + "=" + str(((int(n)+int(n)*10+int(n)+int(n)*100+int(n)*10+int(n))))
digit = input("Please input a digit:")
print(digit +" + "+ digit*2 +" + "+ digit*3 + " = " + str(int(digit)+int(digit*2)+int(digit*3)))
n = int(input("Please input a digit:"))
print(f"{n}+{n}{n}+{n}{n}{n}={(1+11+111)*n}")

在这里插入图片描述

n copies of string

Write a Python program to input a string s and a positive integer n, then output n copies of string s.

string=input("Please input a string:")
integer=input("Please input a positive integer:")
print(integer + " copies of string" + "'"+string+"'" + "is " + "'"+string*int(integer)+"'")
string=input("Please input a string:")
integer=int(input("Please input a positive integer:"))
print(f"{integer} copies of string '{string}' is '{string*integer}'")

在这里插入图片描述

Area of triangle

Write a Python program that will accept the base and height of a triangle and compute the area.

base=input("Input the base : ")
height=input("Input the height :")
print("area =  "+str(int(base)*int(height)/2))

在这里插入图片描述

Sum of two greater than the third?

Write a Python program to input three numbers, and output if the sum of the first two is greater than the third.

first_number=int(input("Please input the first number:"))
second_number=int(input("Please input the second number:"))
third_number=int(input("please input the third number:"))
print(first_number+second_number>third_number)

在这里插入图片描述

Result of expression

Write a Python program to input two integers, x and y, then calculate the expression ( x + y ) 3 (x+y)^3 (x+y)3

x=int(input("x="))
y=int(input("y="))
print((x+y)**3)

在这里插入图片描述

x=int(input("x="))
y=int(input("y="))
print(f"({x}+{y})^3={(x+y)**3}")

在这里插入图片描述

Future value

Write a Python program to compute the future value of input principal amount, rate of interest, and a number of years.

principal_amount=int(input("principal amount:"))
rate_of_interest=float(input("rate of interest:"))
number_of_years=int(input("number of years: "))
print("future value:",principal_amount*(1+rate_of_interest)**number_of_years)

在这里插入图片描述

Distance

Write a Python program to compute the distance between the points (x1, y1) and (x2, y2).
(You may use sqrt from math module.)

from math import *
x1=float(input("x1="))
y1=float(input("y1="))
x2=float(input("x2="))
y2=float(input("y2="))
print(sqrt((x1-x2)**2+(y1-y2)**2))

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值