0% found this document useful (0 votes)
2 views2 pages

Answer Key For Python Codes

The document contains an answer key for various Python programs that perform different tasks. These include calculating the area of a triangle, converting minutes to seconds, joining words, finding the square of a number, converting Celsius to Fahrenheit, printing age, repeating a word, finding the last digit of a number, calculating total and average marks, and finding the remainder of two numbers. Each program is presented with its code and a brief description of its functionality.

Uploaded by

vaishali80shetty
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)
2 views2 pages

Answer Key For Python Codes

The document contains an answer key for various Python programs that perform different tasks. These include calculating the area of a triangle, converting minutes to seconds, joining words, finding the square of a number, converting Celsius to Fahrenheit, printing age, repeating a word, finding the last digit of a number, calculating total and average marks, and finding the remainder of two numbers. Each program is presented with its code and a brief description of its functionality.

Uploaded by

vaishali80shetty
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

ANSWER KEY FOR PYTHON CODES

1. Program to input base and height of a triangle and print the area
base = float(input("Enter base: "))
height = float(input("Enter height: "))
area = 0.5 * base * height
print("Area of triangle:", area)

2. Convert minutes to seconds


minutes = int(input("Enter time in minutes: "))
seconds = minutes * 60
print("Time in seconds:", seconds)

3. Input two words and print them joined (no space)


word1 = input("Enter first word: ")
word2 = input("Enter second word: ")
print(word1 + word2)

4. Program to find the square of a number


num = float(input("Enter a number: "))
square = num * num
print("Square is:", square)

5. Convert Celsius to Fahrenheit


Formula: F = (C × 9/5) + 32
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print("Temperature in Fahrenheit:", f)

6. Enter name and age and print " is years old."


name = input("Enter your name: ")
age = input("Enter your age: ")
print(name, "is", age, "years old.")

7. Enter a word and a number → print the word repeated


word = input("Enter a word: ")
n = int(input("Enter a number: "))
print(word * n)

8. Print the last digit of a number


num = int(input("Enter a number: "))
last_digit = num % 10
print("Last digit:", last_digit)

9. Enter marks of 5 subjects → print total and average


m1 = float(input("Enter marks of subject 1: "))
m2 = float(input("Enter marks of subject 2: "))
m3 = float(input("Enter marks of subject 3: "))
m4 = float(input("Enter marks of subject 4: "))
m5 = float(input("Enter marks of subject 5: "))
total = m1 + m2 + m3 + m4 + m5
average = total / 5
print("Total marks:", total)
print("Average marks:", average)

10. Enter two numbers a, b and print the remainder (a % b)


a = int(input("Enter number a: "))
b = int(input("Enter number b: "))
remainder = a % b
print("Remainder:", remainder)

You might also like