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

Python Prac1

The document describes steps to install Python and PyCharm IDE on Windows. It then provides 4 Python programs: 1) A program to implement all arithmetic operators that takes user input for two numbers and an operation choice. 2) A program to find the largest of three numbers input by the user. 3) A program to display all prime numbers within a range input by the user. 4) The output for each program is also shown.

Uploaded by

Dhruv Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Python Prac1

The document describes steps to install Python and PyCharm IDE on Windows. It then provides 4 Python programs: 1) A program to implement all arithmetic operators that takes user input for two numbers and an operation choice. 2) A program to find the largest of three numbers input by the user. 3) A program to display all prime numbers within a range input by the user. 4) The output for each program is also shown.

Uploaded by

Dhruv Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Patel Dhruv Batch:A 160410116084

Practical 1
AIM : Develop Programs to understand the control structure of python.

1.Write steps to install python and pycharm IDE for Windows Python
Programming.

Steps of Installing python:

Step 1 : To download and install Python visit the official website of Python
http://www.python.org/downloads/ and choose your version.
Step 2 : Once the download is complete, run the exe for install Python. Now click on Install
Now.

Step 3 : Python is installing at this point.


Step 4 : When it finishes, you can see a screen that says the Setup was successful. Now click
on "Close".
Installing Pycharm :

Step 1 : To download PyCharm visit the website


https://www.jetbrains.com/pycharm/download/ and Click the "DOWNLOAD" link under the
Community Section.

Step 2 : Once the download is complete, run the exe for install PyCharm. The setup wizard
should have started. Click “Next”.
Step 3 : On the next screen, Change the installation path if required. Click “Next”.

Step 4 : On the next screen, you can create a desktop shortcut if you want and click on
“Next”.
Step 5 : Choose the start menu folder. Keep selected JetBrains and click on “Install”.

Step 6 : Wait for the installation to finish.


Step 7 : Once installation finished, you should receive a message screen that PyCharm is
installed. If you want to go ahead and run it, click the “Run PyCharm Community Edition”
box first and click “Finish”.

Step 8 : After you click on "Finish," the Following screen will appear.
2.Write a program to implement all arithmetic operators.

num1=eval(input("Enter value of num1: "))


num2=eval(input("Enter value of num2: "))
def add(a,b):
return a+b
def sub(a,b):
return a-b
def mul(a,b):
return a*b
def div(a,b):
return a/b
def mod(a,b):
return a%b
def exp(a,b):
return a**b
print("select operation")
print("1.Addition")
print("2.Subtraction")
print("3.Multiplication")
print("4.Division")
print("5.Modulus")
print("6.Exponent")
choice=eval(input("Enter the choice: "))
if choice==1:
print("Addition is: ",add(num1,num2))
elif choice==2:
print("Subtraction is: ",sub(num1,num2))
elif choice==3:
print("Multiplication is: ",mul(num1,num2))
elif choice==4:
print("Division is: ",div(num1,num2))
elif choice==5:
print("Modulus is: ",mod(num1,num2))
elif choice==6:
print("Exponent is: ",exp(num1,num2))
else:
print("Invalid Input")
Output:

Enter value of num1: 20


Enter value of num2: 10
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 1
Addition is: 30
Enter value of num1: 20
Enter value of num2: 10
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 2
Subtraction is: 10
Enter value of num1: 20
Enter value of num2: 10
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 3
Multiplication is: 200
Enter value of num1: 20
Enter value of num2: 10
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 4
Division is:2.0
Enter value of num1: 5
Enter value of num2: 2
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 5
Modulus is:1.0
Enter value of num1: 2
Enter value of num2: 5
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 6
Exponent is:32.0
Enter value of num1: 20
Enter value of num2: 10
select operation
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
6.Exponent
Enter the choice: 7
Invalid Input
3. Write a program to find largest out of three numbers given by users.

num1=eval(input("Enter value of num1: "))


num2=eval(input("Enter value of num2: "))
num3=eval(input("Enter value of num3: "))

def max(a,b,c):
if (a>b and a>c):
return a
elif (c>a and c>b):
return c
else:
return b
print("Largest number is: ",max(num1,num2,num3))

Output:
Enter value of num1: 43
Enter value of num2: 23
Enter value of num3: 65
Largest number is: 65
4. Display all prime numbers within range given by users.

lower=eval(input("Enter the lower Number:"))


higher=eval(input("Enter the higher Number:"))
l=1
for num in range(lower,higher+1):
if(num>0):
for i in range(2,num):
if(num%i==0):
l=1
break
if(l==1):
l=0
else:
print("prime numbers are: ",num)

Output:
Enter the lower Number:1
Enter the higher Number:20
prime numbers are: 2
prime numbers are: 3
prime numbers are: 5
prime numbers are: 7
prime numbers are: 11
prime numbers are: 13
prime numbers are: 17
prime numbers are: 19

You might also like