-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-calculator.py
67 lines (42 loc) · 1.34 KB
/
python-calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#python calculator (Youtube - 01:01:00)
operator = input("Enter an operator (+ - * /): ")
num1 = float(input("Enter number 1: "))
num2 = float(input("Enter number 2: "))
if operator == "+":
result = num1 + num2
print(f"The result is : {result}")
elif operator == "-":
result = num1 - num2
print("The result is : {result}")
elif operator == "*":
result = num1 * num2
print(f"The result is : {result}")
elif operator == "/":
result = num1 / num2
print(f"The result is : {result}")
else:
print(f"The {operator} is not valid operator")
#python weight converter (pound to kg / kg to pound)
weight = float(input("Enter your weight: "))
unit = input("Kilograms or Pounds? (K or L): ")
if unit == "K":
weight = weight * 2.02
unit = "Lbs"
print (f"Your weight is: {round(weight, 1)} {unit}")
elif unit == "L":
weight = weight / 2.02
unit = "Kg"
print (f"Your weight is {round(weight, 1)} {unit}")
else:
print (f"{unit} is not valid")
# Temprature conversion program
unit = input("Is this temprature in Celcius or Fahrenite? (C/F): ")
temp = float(input("Enter the temprature value: "))
if unit == "C":
temp = 5/9 * ({temp} - 32)
print(f"The temprature in fahrenite is: {temp}")
elif unit == "F":
temp = (9/5) * temp + 32
print(f"The temprature in celcius is: {temp}")
else:
print(f"{unit} unit is invalid")