1)Python Program to Convert Celsius To Fahrenheit:-
Code:-
# Python Program to convert temperature in celsius to fahrenheit
# change this value for a different result
celsius = 37.5
# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
Output:-
37.5 degree Celsius is equal to 99.5 degree Fahrenheit2)Basic gates:-
# Python3 program to illustrate
# working of AND gate
def AND (a, b):
if a == 1 and b == 1:
return True
else:
return False
# Driver code
if __name__=='__main__':
print(AND(1, 1))
print("+---------------+----------------+")
print(" | AND Truth Table | Result |")
print(" A = False, B = False | A AND B =",AND(False,False)," | ")
print(" A = False, B = True | A AND B =",AND(False,True)," | ")
print(" A = True, B = False | A AND B =",AND(True,False)," | ")
print(" A = True, B = True | A AND B =",AND(True,True)," | ")
Output:-
True
+---------------+----------------
| NAND Truth Table | Result |
A = False, B = False | A AND B = True |
A = False, B = True | A AND B = True |
A = True, B = False | A AND B = True |
A = True, B = True | A AND B = False |
Binary number To Decimal:-
# Function to convert Binary number
# to Decimal number
def binaryToDecimal(n):
return int(n,2)
# Driver code
if __name__ == '__main__':
print(binaryToDecimal('100'))
print(binaryToDecimal('101'))
print(binaryToDecimal('1001'))
Output:- 4
5
9
length of String:-
e=input("enter a string:- ")
print(len(e))
print(e +" " + "Medikonda")
Output:-
enter a string:- Rajesh
6
Rajesh Medikonda
Replace Substring:-
e = "My name is Elisha"
x = e.replace("Elisha", "Rajesh")
print(x)
palindrome:-
Palindrome Program using While Loop
num=int(input("Enter a number:"))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("The number is palindrome!")
Output:
Enter a number:121
The number is palindrome!
else:
print("Not a palindrome!")
Palindrome Program using While Loop
num=int(input("Enter a number:"))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("The number is palindrome!")
else:
print("Not a palindrome!")
Output:
Enter a number:121
The number is palindrome!
String:-
string=input(("Enter a string:"))
if(string==string[::-1]):
print("The string is a palindrome")
else:
print("Not a palindrome")
Output :-
Enter a string: RACECAR
Output: Yes, a Palindrome string
Vowel or Not:-
ch = input("Enter a character: ")
if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'
or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
print(ch, "is a Vowel")
else:
print(ch, "is a Consonant")
String Formatting:-
e= input("Enter a name:- ")
print("hi %s,How are you" %e)
Output:-
Enter a name:- rajesh
hi rajesh,How are you
Seven Segment Display:-
zero = '###\n# #\n# #\n# #\n###\n\n'
one = '#\n#\n#\n#\n#\n\n'
two = '###\n #\n###\n# \n###\n\n'
three = '###\n #\n###\n #\n###\n\n'
four = '# #\n# #\n###\n #\n #\n\n'
five = '###\n# \n###\n #\n###\n\n'
six = '###\n# \n###\n# #\n###\n\n'
seven = '###\n #\n #\n #\n #\n\n'
eight = '###\n# #\n###\n# #\n###\n\n'
nine = '###\n# #\n###\n #\n###\n\n'
def seven_segment_display(digit):
if digit >= 0:
digit = str(digit)
digit_list = list(digit)
new_digit = ''
for i in range(len(digit_list)):
if digit_list[i] == '0':
new_digit += zero
if digit_list[i] == '1':
new_digit += one
if digit_list[i] == '2':
new_digit += two
if digit_list[i] == '3':
new_digit += three
if digit_list[i] == '4':
new_digit += four
if digit_list[i] == '5':
new_digit += five
if digit_list[i] == '6':
new_digit += six
if digit_list[i] == '7':
new_digit += seven
if digit_list[i] == '8':
new_digit += eight
if digit_list[i] == '9':
new_digit += nine
return new_digit
print(seven_segment_display(123))
Factorial Using While Loop:-
num = int(input("enter a number: "))
fac = 1
i = 1
while i <= num:
fac = fac * i
i = i + 1
print("factorial of ", num, " is ", fac)
output:-