This document contains 5 Python coding questions and answers from a student named Abdullah Shahzad in Class 9-D. It includes codes to: 1) calculate the quotient and remainder of two numbers, 2) calculate the sum, product, or average of 3 numbers based on user input, 3) interchange the values of two variables using a temporary variable, 4) print the numbers, squares and cubes from 1 to 15, and 5) display the weekday name based on a number from 1 to 7 representing the day of the week.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
58 views
Python Codes Abdullah
This document contains 5 Python coding questions and answers from a student named Abdullah Shahzad in Class 9-D. It includes codes to: 1) calculate the quotient and remainder of two numbers, 2) calculate the sum, product, or average of 3 numbers based on user input, 3) interchange the values of two variables using a temporary variable, 4) print the numbers, squares and cubes from 1 to 15, and 5) display the weekday name based on a number from 1 to 7 representing the day of the week.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
Name: Abdullah Shahzad
Class: 9-D CS Assignment (python codes)
Q1: Write program that will input two variables and
compute their quotient and remainder Code 1 a = int(input("Enter the first number ")) b = int(input("Enter the second number ")) quotient = a // b remainder = a % b print("Quotient", quotient) print("Remainder", remainder) Q2: write program to input any three numbers and print their sum, product and average depending on the user’s choice Code 2 num1 = int(input("Enter the first number")) num2 = int(input("Enter the second number")) num3 = int(input("Enter the third number")) print("1. Sum") print("2. Product") print("3. Average") choice = int(input("Enter your choice (1-3): ")) if (choice == 1): sum = (num1 + num2 + num3) print("Sum is", sum) elif (choice == 2): product = (num1 * num2 * num3) print("Product is:", product) elif (choice == 3): average = (num1 + num2 + num3) / 3 print("Average is", average) Q3: Write program that will input two numbers in two variables and interchange their values using temporary variable than display interchanged value Code 3 num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) print("Original values: num1 =", num1, "and num2 =", num2) temp = num1 num1 = num2 num2 = temp print("Interchanged values: num1 =", num1, "and num2 =", num2)
Q4: write program to print the numbers, its square and
cubes for all natural numbers from 1 to 15 Code 4 for i in range(1, 16): print(i, i**2, i**3)
Q5: Write program to display the name of the weekday
on entry of the number of this weekday Code 5 weekday_num = int(input("Enter a number representing a weekday (1-7)")) weekday_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] weekday_name = weekday_names[weekday_num - 1] print("The weekday corresponding to the number", weekday_num, "is", weekday_name)