0% found this document useful (0 votes)
17 views3 pages

Python Code Snippets for Basic Calculations

Uploaded by

abindammam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Python Code Snippets for Basic Calculations

Uploaded by

abindammam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1)

keep_going='y'

total=0
while keep_going=='y':

sales=float(input('Enter the amount of sales: '))


comm_rate=float(input('Enter commission rate: '))

commission=sales*comm_rate

print("commission is",commission)
total=total+commission
print("Total is",total)
print("Thet total is",total)
2)
n = input("Enter the value :--> ")
absolute = abs(int(n))
print("\nThe absolute value of the number is :-->", absolute)

3)
print("Do you use Fahrenheit (F) or Celcius? (C)")
degreeUnit = (input("Enter F or C : ")).upper()
temp = int(input("What is the temperature of the water? "))
if degreeUnit == "F" and temp <=32: #checking if unit is F and if water is frozen
print("The water is frozen.")
elif degreeUnit == "F" and temp >= 212: #water freezes at 32F is gas at 212 is it gas?
print("The water is a gas")
elif degreeUnit == "F" and temp >=33 or temp <=211:
print("The water is a liquid.")
elif degreeUnit == "C" and temp <=0: #water freezes at 0C
print("The water is frozen.")
elif degreeUnit == "C" and temp >=100: #water is gas at 100C
print("The water is a gas.")
elif degreeUnit == "C" and temp >=1 or temp <=99:
print("The water is a liquid.")
else:
print("invalid input")

4)
print('Enter marks of five subjects: ')
S1=float(input())
S2=float(input())
S3=float(input())
S4=float(input())
S5=float(input())

total = S1 + S2 + S3 + S4 + S5;
average = total/5.0;

print('Total marks = ', total)


print('Average marks = ', average)

5)
print('Enter 3 numbers 50: ')
num1 = float(input())
num2 = float(input())
num3 = float(input())

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is", largest)

6)
n=int(input('Enter num '))
for i in range(0,n):
if( i%2!=0 & i%3!=0 ):
print(i)

You might also like