python programs
python programs
python programs
Write python program using function for the following. Take input from the user.
#Addition of Two Numbers using def funtion and taking users input.
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)
#primenumber.py
def primenumber(n):
#n=int(input("enter any number"))
if n>1:
for x in range(2, n):
if n % x == 0:
print("n is not a prime number")
break
else:
print(n, 'is a prime number')
else:
print("use a real number")
primenumber(10)
def celcius_to_farenheit(celcius):
farenheit = (celcius * 9/5) + 32
return farenheit
celcius = int(input("Enter the temperature in Celcius: "))
farenheit = celcius_to_farenheit(celcius)
print("The temperature in Farenheit is:", farenheit)
7. Fibonacci Sequence
8. Reverse a String
#to print the reverse string using def funtion and taking users input.
def reverse_string():
string = input("Enter a string: ")
reversed_string = string[::-1]
print("The reversed string is:", reversed_string)
reverse_string()
9. Check if a String is a Palindrome
#Check if a String is a Palindrome using def funtion and taking users input.
def is_palindrome(s):
return s == s[::-1] # reverse the string and check if it's equal to the
original string
# Taking user input
string = input("Enter a string: ")
# Checking if the string is a palindrome
if is_palindrome(string):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
#Check if a String is a Palindrome using lambda function and taking users
input.
#Count Vowels in a String using def funtion and taking users input.
string = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = 0
for char in string:
if char in vowels:
count += 1
print("The number of vowels in the string is:", count)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: