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

Programs Of Python Fundamentals (2)

Uploaded by

asadsdsdwdf
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)
5 views

Programs Of Python Fundamentals (2)

Uploaded by

asadsdsdwdf
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

COMPUTER SCIENCE CLASS 11

PYTHON FUNDAMENTALS PRACTISE PROGRAMS

SOLVED QUESTIONS :-

1. Standard program to add two numbers in python.


a = 25
b = 25
sum = a + b
print("The sum of two numbers is:", sum)
Output:
The sum of two numbers is: 50

2. Code to add two numbers in python by taking numbers from the user.
x = int(input("Enter First Number:\n"))
y = int(input("Enter Second Number:\n"))
Sum = x+y
print("Sum of", x, "and", y, "is", Sum)

Output:
Enter First Number: 12
Enter Second Number: 32
Sum of 12 and 32 is 44

3. Python program to input and output your name.


var = input("Enter your name:")
print("Name you have entered is: ", var)
Output:
Enter your name: abc
Name you have entered is: abc

4. Program to obtain three numbers and print their sum.


# to input 3 numbers and print their sum
num1 =int(input("Enter number 1 :"))
num2 =int(input("Enter number 2: "))
num3 = int(input("Enter number 3: "))
Sum = num1 + num2 + num3
print("Three numbers are: ",num1,num2,num3)
print("Sum is: ", Sum)

Output:
Enter number 1: 7
Enter number 2: 3
Enter number 3: 13
Three numbers are: 7 3 13
Sum is : 23
5. Program to obtain length and breadth of a rectangle and calculate its area.
# to calculate area
length = float(input("Enter length of the rectangle :"))
breadth = float(input("Enter breadth of the rectangle :"))
area = length * breadth
print ("Length = ", length)
print ("breadth = ", breadth)
print ("Area = ", area)

Output:
Enter length of the rectangle : 8.75
Enter breadth of the rectangle: 35.0
Length = 8.75
Breadth = 35.0
Area = 306.25

6. Write a program to obtain temperature in Celsius and convert it into Fahrenheit


using formula.
°C x 9 / 5 + 32 = °F
# Celsius to Fahrenheit
C = float(input("Enter temp in Celsius :"))
print ("Temperature in Celsius is :", C)
F = C*9/5+32
print ("Temperature in Fahrenheit is :", F)

Output:
Enter temp in Celsius : 15
Temperature in Celsius is : 15
Temperature in Fahrenheit is : 59

7. Python Program to Swap Two Variables.

[By Using a temporary variable]


# Python program to swap two variables
x = 5
y = 10
# create a temporary variable and swap the values
temp = x
x = y
y = temp
print('The value of x after swapping :',x)
print('The value of y after swapping : ',y)

Output:
The value of x after swapping : 10
The value of y after swapping : 5
[Without Using Temporary Variable]
x = 5
y = 10
x, y = y, x # multiple assignment property
print("x =", x)
print("y =", y)

Output:
x = 10
y=5

OR
x = 5
y = 10
x = x + y
y = x - y
x = x - y
print("x =", x)
print("y =", y)

Output:
x = 10
y=5

8. Write a program that generates the following output:


5
10
9
Assign value 5 to a variable using assignment operator (=) Multiply it with 2 to
generate 10 and subtract 1 to generate 9.
a = 5
print(a)
a *= 2
print(a)
a -= 1
print(a)

ASSIGNMENT:-

1. Write a program with a maximum of three lines of code and assign the first 5
multiples of a number to 5 variables and then print them.
2. Write a Python program that accepts the radius of a circle and prints its area.
3. Write a program to read a number n and print n², n³, n⁴.
4. Write a program to find the area of a triangle.
5. Predict the output of the following code:-
a) a, b, c = 2, 3, 4
a, b, c = a*a, a*b, a*c
print(a, b, c)
b) first = 2
second = 3
third = first + second
print(first, second, third)
first = first + second + third
third = second * first
print(first, second, third)

c) X = 10
X = X + 10
X = X - 5
print(X)
X, Y = X-2, 22
print(X, Y)

d) side = int(input('side')) # side given as 7


area = side * side
print(side, area)

6. What is the problem(error) with the following code fragments?

a) a = 3
print(a)
b = 4
print(b)
s = a + b
print(s)

b) name = "Prajith"
age = 26
print("Your name & age are ", name + age)

c) a = 3
s = a + 10
a = "New"
q = a / 10
print(q)

hello madam mai na 3 hfto se wait kr rha thaki ab baat krog ab krogi! lekin tumne nhi tumne school me baat krne se mana mai kisi ke samne tmse

baat tk nhi krta aur akele tum rheti nhi ho school mai koi na koi tumhare sath ota tumse eyecontact krne ki koshish tum waha se hatt jati rajat se kuch

khane ke bejta tha tum wo bhi mana kr deti thi ......class me tum sbse baat krti ho sirf mujhe chod kr baar baar tumhe durr se koshish krta kabhi

ground se toh kabhi commerce ki window se pr koi na koi aa jata hai.devsena dekho tm baar kahe ki tum mujhse baat nhi chahti mai sach mai tumhe

disturb nhi pr please baat ko tlna nhi .mai na 5 dino tumhri coaching aata hu phir ghr ke aas pass gumta hu kaogi toh proof ke liye maine video bana

rakhi hai mai bej dunga agr tum kaogi toh! tum bs ek baar kahe do ki tumhe chidd hoti dekh tumhe disturb hota hai mai sach me aj ke baad kayi pr

bhi tummhe pareshan nhi krunga. kasam se bs ek baar likh class me bhi sochta rhetaki ab koi kaam bologi mujhse pr rajat tanish keshav aatrey inhi

ka naam leti kl bhi . areh tumse kuch mt krawao tum mujse agr pani ki bootle br do tum bag utha lau toh mai ye bhi khusi khusi kr dunga .. pr agr

baat krni hai toh kro wrna plss mana kr do jaise 1.5 saal bina baat kiye rha waise abhi bhi rhe lunga

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy