Python LAB Solution PRAYOSHA GTU
Python LAB Solution PRAYOSHA GTU
STEP 1 : START
STEP 4 : Sum=Number1+Number2
STEP 6 : STOP
Step 1: Start
Step 4: End
Step 1: Start
Step 4: End
Step 1:Star
Step 8:end
Python is a very easy-to-learn and powerful programming language. And that's why it's gaining so
much popularity among people looking to start programming.
Python doesn't have complicated syntax or difficult rules. At its core, Python is a practical
programming language that's used in:
Web development
Data analysis
Artificial intelligence
Natural language processing
Scientific computing
You can also build lots of different web, desktop, or Smartphone apps in Python. With its various
modules, Python makes it easy to learn new programming concepts and build increasingly
complex applications.
Windows
Mac OS
Linux
If you're on Windows, there's more than one way to install Python. You can download the 32-bit
or 64-bit version of Python using a(n):
Web installer
Executable (.exe) installer
Zip file
We'll download Python 3.7.0 using the executable installer (python-3.7.0-amd64.exe). Why this
kind of installer? Because it has flexible user interface and contains all we need to write and run
our scripts in Python.
Once you download the installer, run it and follow the steps below.
In the first installation window, we can choose type of installation: Install Now or Customize. If
you don't want to change the installed tools or settings, choose the first option. Also, be sure to
check the Add Python 3.7 to PATH box at the bottom of the window to inform your OS where it
can find the Python executable so that it may be invoked from the command line.
In your Start menu, you should see a list of Python 3.7 tools.
Practical 3. Create a program to print your name, mobile number, and date ofbirth.[CO2]
a=5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
Practical 5. Create a program to read three numbers from the user and find
the average of the numbers. [CO2]
# calculate average
avg = (num1 + num2 + num3)/3
# display result
print('The average of numbers = ‘,avg)
# Calcualtion
simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)
# Displaying result
print('Simple interest is: %f' % (simple_interest))
Fahrenheit= 54
Celsius = ((Fahrenheit-32)/1.8)
print("Temperature in Celsius is: ");
print(Celsius);
Practical 8. Identify whether the scanned number is even or odd and print an appropriate
message.
Practical 9. Create a program to find a maximum number among the given three
numbers.
if select == 1:
print(number_1, "+", number_2, "=", number_1+number_2)
elif select == 2:
print(number_1, "-", number_2, "=", number_1-number_2)
elif select == 3:
print(number_1, "*", number_2, "=", number_1*number_2)
elif select == 4:
print(number_1, "/", number_2, "=", number_1/number_2)
else:
print("Invalid input")
3. Multiply
4. Divide
maximum))
Practical 12. Develop a program to find odd and even numbers from 1 to N numbers.
(Where N is an integer number).
Practical 13. Write a program to show whether the entered number is prime or not.
A. B.
rows = 6; rows = 5
# outer loop b=0
for i in range(rows): # reverse for loop from 5 to 0
# nested loop for i in range(rows, 0, -1):
for j in range(i): b += 1
# display number for j in range(1, i + 1):
print(j+1, end=' ') print("*", end=' ')
# new line after each row print('\r')
print('')
OUTPUT: 1 *****
12 ****
123 ***
1234 **
12345 *
Practical 15. Create a program to find a maximum number among the given three
numbers.
def Fibonacci(n):
if n<0:
print("Incorrect input")
# First Fibonacci number is 0
elif n==0:
return 0
# Second Fibonacci number is 1
elif n==1:
return 1
else:
return Fibonacci(n-1)+Fibonacci(n-2)
Practical 16. Develop a user-defined function to find the factorial of a given number.
Practical 17. Write a program using the function that reverses the entered value.
revr_num = recur_reverse(num)
print("n Reverse of entered number is = %d" % revr_num)
OUTPUT: Enter the number: 12345
n Reverse of entered number is = 54321
Practical 18. Write a program that determines whether a given number is an Armstrong
number or a palindrome using a user-defined function.
Temp = Number
while Temp > 0:
Times = Times + 1
Temp = Temp // 10
Temp = Number
while Temp > 0:
Reminder = Temp % 10
Sum = Sum + (Reminder ** Times)
Temp //= 10
if Number == Sum:
print("\n %d is Armstrong Number.\n" %Number)
else: