0% found this document useful (0 votes)
3 views12 pages

CS Project Code

The document contains a Python program that provides various unit conversion functionalities, including numeral systems, length, weight, and time conversions. Users can select the type of conversion they want and follow prompts to input values and receive converted results. The program allows users to restart conversions or return to the main menu for other conversion options.

Uploaded by

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

CS Project Code

The document contains a Python program that provides various unit conversion functionalities, including numeral systems, length, weight, and time conversions. Users can select the type of conversion they want and follow prompts to input values and receive converted results. The program allows users to restart conversions or return to the main menu for other conversion options.

Uploaded by

dihiyi7425
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Program Code

def main():

c= int(input('''

1. Numeral Systems

2. Length

3. Weight

4. Time

Enter the S.no. of converter : '''))

def numsys():

if c==1:

print("Numeral System Converter")

n=int(input('''Choose the number system converter :

-> Decimal to Binary(1)

-> Binary to Decimal(2)

-> Decimal to Octal(3)

-> Octal to Decimal(4)

-> Decimal to Hexadecimal(5)

-> Hexadecimal to Decimal(6)

'''))

if n==1:

d= int(input("Enter decimal no. : "))

b= str(bin(d))

b2= b.replace("0b","")

print(d,"in Binary is ",int(b2))

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()
elif n==2:

b=input("Enter Binary no. : ")

l=list(b)

sum=0

l.reverse()

for i in range(len(l)):

sum+=int(l[i])*2**i

print(b, "in Binary = ", sum, "in Decimal.")

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()

elif n==3:

d= int(input("Enter decimal no. : "))

b= str(oct(d))

b2= b.replace("0o","")

print(d,"in Octal is ",int(b2))

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()

elif n==4:

o=input("Enter Octal no. : ")

l=list(o)

sum=0
l.reverse()

for i in range(len(l)):

sum+=int(l[i])*8**i

print(o, "in Octal = ", sum, "in Decimal.")

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()

elif n==5:

d= int(input("Enter decimal no. : "))

b= str(hex(d))

b2= b.replace("0x","")

print(d,"in Hexadecimal is ",b2)

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()

elif n==6:

hexadecimal = input("Enter a hexadecimal number: ").upper()

hex_dict = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5,


'6':6, '7':7, '8':8, '9':9, 'A':10, 'B':11, 'C':12, 'D':13, 'E':14, 'F':15}

decimal = 0

power = 0
for digit in hexadecimal[::-1]:

decimal += hex_dict[digit] * (16**power)

power += 1

print(hexadecimal, "in hexadecimal = ", decimal, "in


Decimal.")

r=int(input('''Press (1) to restart Numeral System


Converter

Press (2) for Converter options

'''))

if r==1:

numsys()

elif r==2:

main()

numsys()

def lenco():

if c==2 :

print("Length Converter")

n=int(input('''Choose the Length converter :

-> c.m. to in(1)

-> c.m. to m(2)

-> in to ft(3)

-> k.m. to mi(4)

-> m to yd(5)

'''))

if n==1:

centimetres = float(input("Enter the length in centimetres:


"))

inches = centimetres/2.54

print(centimetres, "c.m. in inches is:", inches)


r=int(input('''Press (1) to restart Length Converter

Press (2) for Converter options

'''))

if r==1:

lenco()

elif r==2:

main()

if n==2:

centimetres= float(input("Enter the length in centimetres:


"))

metres = centimetres/100

print(centimetres, "c.m.in metres is :", metres, "m")

r=int(input('''Press (1) to restart Length Converter

Press (2) for Converter options

'''))

if r==1:

lenco()

elif r==2:

main()

if n==3:

inches = float(input("Enter the number of inches: "))

feet = inches / 12

print(inches, "in in feet is :", feet, "ft")

r=int(input('''Press (1) to restart Length Converter

Press (2) for Converter options

'''))

if r==1:

lenco()

elif r==2:

main()

if n==4:
kilometers = float(input("Enter the distance in kilometres:
"))

miles_per_kilometer = 0.621371

miles = kilometers * miles_per_kilometer

print(kilometers, "k.m. in miles is:", miles, "mi")

r=int(input('''Press (1) to restart Length Converter

Press (2) for Converter options

'''))

if r==1:

lenco()

elif r==2:

main()

if n==5:

metres = float(input("Enter the distance in metres: "))

yards = metres * 1.094

print(metres, "m in yards is: ", yards, "yd")

r=int(input('''Press (1) to restart Length Converter

Press (2) for Converter options

'''))

if r==1:

lenco()

elif r==2:

main()

lenco()

def weco():

if c==3:

print("Weight Converter")

n=int(input('''Choose the Weight converter :

-> Gram to Milligram(1)

-> Ounce to Gram(2)

-> Tonne to Kilograms(3)

-> Quintal to Kilograms(4)

-> Kilogram to Pound(5)


'''))

if n==1:

g=float(input("Enter weight in Grams: "))

mg=g*1000

print(g, "g in milligrams is : ", mg,"mg")

r=int(input('''Press (1) to restart Weight Converter

Press (2) for Converter options

'''))

if r==1:

weco()

elif r==2:

main()

if n==2:

oz=float(input("Enter weight in Ounces: "))

g= o*28.35

print(oz, "oz in grams is : ", g,"g")

r=int(input('''Press (1) to restart Weight Converter

Press (2) for Converter options

'''))

if r==1:

weco()

elif r==2:

main()

if n==3:

t= float(input("Enter weight in Tonnes: "))

kg= t*1000

print(t,"t in kilograms is: ", kg,"kg")

r=int(input('''Press (1) to restart Weight Converter

Press (2) for Converter options

'''))

if r==1:

weco()

elif r==2:

main()
if n==4:

q=float(input("Enter wieght in Quintal: "))

kg=q*100

print(q,"q in kilograms is: ", kg,'kg')

r=int(input('''Press (1) to restart Weight Converter

Press (2) for Converter options

'''))

if r==1:

weco()

elif r==2:

main()

if n==5:

kg=float(input("Enter weight in Kilograms: "))

lb=kg*2.20

print(kg, "kg in pounds is : ", lb,"lb")

r=int(input('''Press (1) to restart Weight Converter

Press (2) for Converter options

'''))

if r==1:

weco()

elif r==2:

main()

weco()

def time():

if c==4:

print("Time Converter")

n=int(input('''Choose the Time converter :

-> Seconds to Minutes and Seconds(1)

-> Seconds to Hours(2)

-> Minutes to Days(3)

-> Minutes to Years(4)

'''))

if n==1:

s= int(input("Enter no. of seconds: "))


m= s//60

s2= s%60

print(s, "seconds equal to: ", m, "mins and ", s2, "secs")

r=int(input('''Press (1) to Time Converter

Press (2) for Converter options

'''))

if r==1:

time()

elif r==2:

main()

if n==2:

s= int(input("Enter no. of seconds: "))

h= s/3600

print(s, "sec equalt to: ", h,"h")

r=int(input('''Press (1) to Time Converter

Press (2) for Converter options

'''))

if r==1:

time()

elif r==2:

main()

if n==3:

minutes = int(input("Enter the number of minutes: "))

days = minutes // 1440

remaining_minutes = minutes % 1440

print(minutes, "minutes is equal to", days, "days and ",


remaining_minutes, "minutes.")

r=int(input('''Press (1) to Time Converter

Press (2) for Converter options

'''))

if r==1:

time()

elif r==2:

main()

if n==4
if n==4:

minutes = int(input("Enter the number of minutes: "))

year_in_minutes = 365 * 24 * 60

years = minutes / year_in_minutes

print(minutes ,"minutes is equal to", years ,"years")

r=int(input('''Press (1) to Time Converter

Press (2) for Converter options

'''))

if r==1:

time()

elif r==2:

main()

time()

main()
Output
1. Numeral Systems

2. Length

3. Weight

4. Time

Enter the S.no. of converter : 1

Numeral System Converter

Choose the number system converter :

-> Decimal to Binary(1)

-> Binary to Decimal(2)

-> Decimal to Octal(3)

-> Octal to Decimal(4)

-> Decimal to Hexadecimal(5)

-> Hexadecimal to Decimal(6)

Enter a hexadecimal number: 11A

11A in hexadecimal = 282 in Decimal.

Press (1) to restart Numeral System Converter

Press (2) for Converter options

1. Numeral Systems

2. Length

3. Weight

4. Time

Enter the S.no. of converter : 3

Weight Converter

Choose the Weight converter :

-> Gram to Milligram(1)

-> Ounce to Gram(2)

-> Tonne to Kilograms(3)

-> Quintal to Kilograms(4)

-> Kilogram to Pound(5)

2
Enter weight in Ounces: 12.1

12.1 oz in grams is : 343.035 g

Press (1) to restart Weight Converter

Press (2) for Converter options

1. Numeral Systems

2. Length

3. Weight

4. Time

Enter the S.no. of converter : 2

Length Converter

Choose the Length converter :

-> c.m. to in(1)

-> c.m. to m(2)

-> in to ft(3)

-> k.m. to mi(4)

-> m to yd(5) 4

Enter the distance in kilometres: 1.6

1.6 k.m. in miles is: 0.9941936 mi

Press (1) to restart Length Converter

Press (2) for Converter options

You might also like