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

Python Program To Convert Celsius To Fahrenheit. Conversion From Celsius To Fahrenheit Temperature

Uploaded by

196unnati
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)
20 views

Python Program To Convert Celsius To Fahrenheit. Conversion From Celsius To Fahrenheit Temperature

Uploaded by

196unnati
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/ 4

1 python program to convert celsius to fahrenheit.

Conversion from celsius to


fahrenheit temperature.
Ans : celsius = int(input("Enter the Temperature in Celsius :\n"))

fahrenheit = (1.8 * celsius) + 32

print("Temperature in Fahrenheit :", fahrenheit)

2 Write a program to enter two integers and perform all arithmetic operations on them.

Ans num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

print("Addition: ",num1 + num2) # Addition

print("Subtraction: ",num1 - num2) # Subtraction

print("Multiplication: ",num1 * num2) # Multiplication

print("Division: ",num1 / num2) # simple Division

print("Floor Division: ",num1 // num2) # floor/ integer Division

print("Modulus: ", num1 % num2) # Modulus

print("Exponentiation: ",num1 ** num2) # Exponentiation

3Create Functions in Python to calculate Area and Perimeter of Circle. Write a Python program to ask
user to input their choice 1 or 2. If choice is 1 calculate Area of Circle, if choice is 2 calculate Perimeter of
Circle otherwise show an error message.

Ans :import math

radius = float(input("Enter the radius of the circle: "))

# Calculate the area of the circle


area = math.pi * radius ** 2

# Calculate the perimeter of the circle


perimeter = 2 * math.pi * radius

print("Area of the circle:", area)


print("Perimeter of the circle:", perimeter)
4. Write a functions in Python to multiply two integer numbers without using the * operator, using
repeated addition

Answer: def multiply(x, y):

if y < 0:

return -multiply(x, -y)

elif y == 0:

return 0

elif y == 1:

return x

else:

return x + multiply(x, y - 1)

print(multiply(3, 5));

5. Write program in python to print the given opposite flyod triangle.

(opposite right angle triangle)

Ans:print("Enter the Number of Rows: ", end="")


row = int(input())

num = 1
for i in range(row):
for j in range(i+1):
print(num, end=" ")
num = num+1
print()

6. ̥Create
–l a function to check the given string is palindrome. If
Palindrome then return True otherwise return False.

Ans : def isPalindrome(string):


if (string == string[::-1]) :
return "The string is a palindrome."
else:
return "The string is not a palindrome."

string = input ("Enter string: ")

print(isPalindrome(string))

7.
7.Create a Function to Guess_Numbers(), which ask a number between 1 to
6 form user. Generate a random number between 1 to 6 through random
module and check the User Guess is matched or not. Display appropriate
message,.

Ans

import random

# Generate a random number between 1 and 10 (inclusive) as the target number


target_num, guess_num = random.randint(1, 10), 0

# Start a loop that continues until the guessed number matches the target number
while target_num != guess_num:
# Prompt the user to input a number between 1 and 10 and convert it to an integer
guess_num = int(input('Guess a number between 1 and 10 until you get it right : '))

# Print a message indicating successful guessing once the correct number is guessed
print('Well guessed!'

8. Write a method/function DISPLAYWORDS() in python to read lines from a text file


STORY.TXT, and display those words, which are less than 4 characters.

Ans def DISPLAYWORDS() :


file = open("story.txt", "r")
lst = file.readlines()
for i in lst :
word = i.split()
for j in word :
if len( j ) < 4 :
print( j )
file.close()

print("Word with length smaller than 3 :- \n")


DISPLAYWORDS()

9. Write a function in python to count the number of lines in a text file ‘STORY.TXT’ which is starting with an alphabet ‘A’ .

Ans: def COUNTLINES():

file=open('STORY.TXT','r')

lines = file.readlines()

count=0

for w in lines:

if w[0]=="A" or w[0]=="a":

count=count+1
print(“Total lines “,count)

file.close()

You might also like