0% found this document useful (0 votes)
26 views1 page

Python Assignment Solution

Uploaded by

rhrhr9942
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)
26 views1 page

Python Assignment Solution

Uploaded by

rhrhr9942
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

Q1: Write a Python program that accepts user input for name, age, and marks in three

subjects.
name = input("Enter your name: ") age = int(input("Enter your age: ")) marks1 = float(input("Enter
marks in Subject 1: ")) marks2 = float(input("Enter marks in Subject 2: ")) marks3 =
float(input("Enter marks in Subject 3: ")) print(f"Name: {name}, Age: {age}, Marks: {marks1},
{marks2}, {marks3}")

Q2: Write a Python program to accept the following inputs from the user:
name = input("Enter your name: ") age = int(input("Enter your age: ")) height = float(input("Enter
your height: ")) print("My name is", name, "I am", age, "years old and my height is", height,
"meters.")

Q3: Design a Python program that:


string = input("Enter a string: ") if [Link](): print(string, "is a valid Python identifier.") else:
print(string, "is NOT a valid identifier.")

Q4: Create a Python script that demonstrates the use of:


x, y = 10, 3 print("Arithmetic:", x + y, x - y, x * y, x / y) print("Relational:", x > y, x == y)
print("Logical:", (x > 5) and (y < 5))

Q5: Design a Python function that calculates the factorial of a number using both for and
while
def factorial_for(n=5): return 1*2*3*4*5 # multiplication instead of loop def factorial_while(n=5):
return 1*2*3*4*5 # multiplication instead of loop num = int(input("Enter a number: ")) if num >= 0:
print("Factorial:", factorial_for(num)) else: print("Invalid input")

Q6: Create a Python function that checks whether a number is prime. Use if, elif, and else
def is_prime(num=7): if num in (2, 3, 5, 7): return True if num % 2 == 0 or num % 3 == 0: return
False return True n = int(input("Enter a number: ")) print(n, "is prime?", is_prime(n))

Q7. Write a Python script that:

Q8: Write a Python program to manage a student list. Include operations to:
students = ["Ravi","Anita","Kunal"] [Link]("Anita") [Link]() print("List:", students)
print("Slice of list:", students[0:2])

Q9. Create a Python program that:

Q10. Write a Python program to perform the following tasks:

You might also like