Sie sind auf Seite 1von 11

School of Engineering and Technology

4BCS105: Programming with Python


Report on Class Project

Submitted by:
Name: AKASH YADAV
USN: 18BBTCS006
Branch: Computer science
Class and Batch: A and AL1
Index

Sl. No Topics Page No


1 Instructions 1
2 Print statement 2
3 Checking whether a 3
number is even or odd
4 Grade obtained by student 4
5 Largest of three numbers 5 to 6
6 Addition, subtraction, 7
multiplication and
division of two numbers
7 Print even and odd 8
numbers from 1 to 100
8 Program a Dice 9
Instructions:
1)To create directory type:
Mkdir <directory name>

2)To change the directory:


cd <directory name>

3)To check current directory type:


Pwd (present working directory)

4)To go back to previous directory type:


cd ..

5)To start python in terminal type:


python3

6)To close python editor type:


Exit()

7)To open/create a text file:


gedit <filename>.txt

8)To clear everything on terminal:


clear

9)To open sublime text type:


subl

10)To run a program type:


python3 <filename>.py
Program 1
Print statement

Code:
#print statement displays output in the
console or terminal
print(“Python is a scripting language and
python is fun!”)

Output:

Python is scripting a language and python is


fun!
Program 2
Check whether the number is
odd or even

Code:
#to get input from user
x = int(input("type a number"))

#displaying whether input number is odd or even


if (x%2==0):
print (x, " is an even number.")
else:
print (x, "is an odd number.")

Output:

Enter a number: 98
98 is Even
Enter a number: 21
21 is Odd
Program 3
Grade obtained by student
Code:
#getting marks obtained in the 3 subjects as input
print("Enter marks obtained in 3 subjects: ")
mark1 = int(input(“mark1: ”))
mark2 = int(input(“mark2: ”))
mark3 = int(input(“mark3: ”))

#summing and finding the average


sum = mark1 + mark2 + mark3
average = sum/3;

#comparing the average with set grades and printing


if(average>=100 and average<=71):
print("Your Grade is A")

elif(average>=51 and average<=70):


print("Your Grade is B")

elif(average>=41 and average<=50):


print("Your Grade is C")

else:
print("Your Grade is Fail")

Output:
Enter marks obtained in 3 subjects:
mark1: 80
mark2: 50
mark3: 65
Your Grade is B
Program 4
Largest of three numbers
Code
#Find largest among numbers

num1,num2,num3 = map(float, input("enter


numbers ").split())

if (num1 >= num2) and (num1 >= num3):


largest = num1

elif (num2 >= num1) and (num2 >= num3):


largest = num2

else:
largest = num3

print("The largest number


between",num1,",",num2,"and",num3,"is",largest)

Output:

enter numbers 12 36 56
The largest number between 12.0 , 36.0 and 56.0
is 56.0
enter numbers 78 96 111
The largest number between 78.0 , 96.0 and
111.0 is 111.0
Program 5
Addition, subtraction, multiplication
and division of two numbers

Code
#simple calculator
#fuction for addition
def add(x, y):
return x + y

#fuction for subtraction


def subtract(x, y):
return x - y

#fuction for multiplication


def multiply(x, y):
return x * y

#fuction for division


def divide(x, y):
return x / y

print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

choice = input("Enter choice(1/2/3/4):")

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))

if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':


print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':


print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")

Output:
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4):1
Enter first number: 12
Enter second number: 36
12 + 36 = 48
Enter choice(1/2/3/4):2
Enter first number: 88
Enter second number: 66
88 - 66 = 22
Enter choice(1/2/3/4):3
Enter first number: 45
Enter second number: 67
45 * 67 = 3015
Enter choice(1/2/3/4):4
Enter first number: 99
Enter second number: 2599 / 25 = 3.96
Program 6
Print odd and even numbers
from 0 to 100

Code
print(“Even numbers from 0 to 100 are: ”)

#loop to print even numbers from 0 to 100

for e in range(0,100):
if i % 2 == 0:
print(i)

print(“Odd numbers from 0 to 100 are: ”)

#loop to print odd numbers from 0 to 100

for o in range(0,100):
if i % 2 == 1:
print(i)

Output:

Even numbers from 0 to 100 are:


0 2 4 6 8 10 12 ………… 98 100(in new lines)

Odd numbers from 0 to 100 are:


1 3 5 7 9 11 ………… 97 99 (in new lines)
Program 7
Rolling Dice

Code
#adding random module to the code to generate
random integer
import random

#to repeat until quit voluntarily


while True:
x = input("Press r to roll the dice\n
Press q to quit:\n")

if x == "r":
print("You got:",random.randint(1,6))

if x == "q":
print("THE END")
quit()

Output:

Press r to roll the dice


Press q to quit: r
You got: 6
Press r to roll the dice
Press q to quit: q
THE END

Das könnte Ihnen auch gefallen