0% found this document useful (0 votes)
27 views

19 To 20 Programs

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)
27 views

19 To 20 Programs

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
You are on page 1/ 2

Aim: Write a python script to find GCD of two numbers using recursive

Source Code:
def gcd(a,b):
if(b==0):
return a
else:
returngcd(b,a%b)
a=int(input(“Enter first number:”))
b=int(input(“Enter second number:”))
GCD=gcd(a,b)
print(“GCD is: “,GCD)

Test Case – 1
User Output
Enter first number: 12
Enter second number: 6
GCD is: 6
Experiment:8
Write a python script to convert the following using functions:
(i) Fahrenheit to Celsius temperature.
(ii) Celsius to Fahrenheit temperature.

a) Aim:Write a Python program to convert temperatures to and from Celsius, Fahrenheit.


Source Code:
temp=input(“Enter the temperature in Celsius or Fahrenheit: “)
d=int(temp[:-1])
i=temp[-1]
if i.upper()==”C”:
r = int(round((d*9)/5+32))
h=”Fahrenheit”
elifi.upper()==”F”:
r= int(round((d-32)*(5/9)))
h=”Celsius”
print(f”The temperature in {h} is {r} degrees”)

Test Case – 1
User Output
Enter the temperature in celsius or Fahrenheit: 215c
The temperature in Fahrenheit is 419 degrees
b) Write a python program to convert the temperature from Celsius to Fahrenheit
Source code:
celsius = 37.5
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))

Test Case-1
User Output
37.5 degree Celsius is equal to 99.5 degree Fahrenheit

You might also like