Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

URA302 - Python-Programming - URA302 - (Lab - Assignment - 1) .Ipynb at Main Sparsh0106 - URA302 - Python-Programming

Python Solution sheets

Uploaded by

rohit.kumar
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)
15 views

URA302 - Python-Programming - URA302 - (Lab - Assignment - 1) .Ipynb at Main Sparsh0106 - URA302 - Python-Programming

Python Solution sheets

Uploaded by

rohit.kumar
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/ 5

sparsh0106 /

URA302---Python-Programming

Code Issues Pull requests Actions Projects Security Insights

URA302---Python-Programming / URA302_(Lab_Assignment_1).ipynb

sparsh0106 Created using Colab (uploaded by Sparsh Agarwal) f407f27 · last month

613 lines (613 loc) · 15.3 KB

Preview Code Blame Raw


Open in Colab

Q1. Write a Python program to print the following string in a specific format (see the
output). Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up
above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I
wonder what you are".

In [ ]: print('"Twinkle, twinkle, little star,\nHow I wonder what you are!\nUp abov

"Twinkle, twinkle, little star,


How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are"

Q2. Write a Python program that accepts the user's first and last name and prints
them in reverse order with a space between them.

In [ ]: first_name = input("Enter first name : ")


last_name = input("Enter last name : ")
print(last_name + " " + first_name)

Enter first name : Sparsh


Enter last name : Agarwal
Agarwal Sparsh

Q3. Write a Python program that calculates the area of a circle based on the radius
entered by the user.

In [ ]: r = float(input("Enter the radius of the circle : "))


area = 22/7 * r * r
print("The area of the circle is:",area)

Enter the radius of the circle : 7


The area of the circle is: 154.0

Q4. Write a Python program to display the first and last colors from the following
list. color_list = ["Red","Green","White" ,"Black"]

In [ ]: color_list = ["Red","Green","White" ,"Black"]


print("First colour:",color_list[0])
print("Second colour:",color_list[3])

First colour: Red


Second colour: Black

Q5. Write a Python program that accepts an integer (n) and computes the value of
n+nn+nnn

In [ ]: n = input("Enter n : ")
print(int(n) + int(2*n) + int(3*n))

Enter n : 5
615

Q6. Write a Python program that accepts a sequence of comma-separated numbers


from the user and generates a list and a tuple of those numbers. Sample data : 3, 5,
7, 23

In [ ]: x = str(input("Enter some numbers : ")).split(",")

l =[]
for i in x:
l.append(int(i))

print(l)
l = tuple(l)
print(l)

Enter some numbers : 1,2,3


[1, 2, 3]
(1, 2, 3)

Q7. Write a program that will convert celsius value to Fahrenheit.

In [ ]: c = float(input("Enter Celcius value : "))


f = 1.8*c + 32
print(f)

Enter Celcius value : 30


86.0

Q8. User will input (2numbers). Write a program to swap the numbers. Add
incrementally in any one variable.

In [ ]: a = float(input("Enter no. 1: "))


b = float(input("Enter no. 2: "))
a,b = b,a
print(a,b)
a += 1
print(a)

Enter no. 1: 2
Enter no. 2: 3
3.0 2.0
4.0

Q9. Write a program that will tell whether the number entered by the user is odd or
even.

In [ ]: x = float(input("Enter a no. : "))


if x%2 == 0:
print("Even")
else:
print("Odd")

Enter a no. : 5.5


Odd

Q10. Write a program that will tell whether the given year is a leap year or not.

I [ ]
In [ ]: year = int(input("Enter year : "))
if year%4 == 0:
print("Leap year")
else:
print("Not a leap year")

Enter year : 2024


Leap year

Q11. Write a program to find the euclidean distance between two coordinates.

In [ ]: x1 = float(input("Enter x1 : "))
x2 = float(input("Enter x2 : "))
y1 = float(input("Enter y1 : "))
y2 = float(input("Enter y2 : "))

d = ((x2-x1)**2 + (y2-y1)**2)**0.5
print(d)

Enter x1 : 0
Enter x2 : 5
Enter y1 : 0
Enter y2 : 5
7.0710678118654755

Q12. Write a program that take a user input of three angles and will find out
whether it can form a triangle or not.

In [ ]: angle_1 = float(input("Angle 1 : "))


angle_2 = float(input("Angle 2 : "))
angle_3 = float(input("Angle 3 : "))
if (angle_1 + angle_2 + angle_3) == 180:
print("Possible")
else:
print("not possible")

Angle 1 : 60
Angle 2 : 59.9
Angle 3 : 60.1
Possible

Q13. WAP to find compound interest for given values.

In [ ]: P = float(input("Enter principal amount : "))


r = float(input("Enter rate : "))
t = float(input("Enter time : "))
n = int(input("Enter n : "))
A = P*((1 + (r/n))**(n*t))
print(A-P)

Enter principal amount : 10000


Enter rate : 0.05
Enter time : 2
Enter n : 1
1025.0

Q14. Given a positive integer N, the task is to write a Python program to check if the
number is Prime or not in Python.

In [ ]: N = int(input("Enter a no : "))
N = int(input( Enter a no. : ))
c = 0
for i in range(2, N):
if N%i == 0:
c += 1

if c > 0:
print("Not prime")
else:
print("Prime")

Enter a no. : 41
Prime

You might also like