You are on page 1of 15

7/26/23, 10:41 AM JavaMx

In [ ]: 1 # STARTING OF NEW JOURNEY OF LANGUAGE PYTHON

In [1]: 1 print ("Hello World")

Hello World

In [1]: 1 a=int(input("enter a no." ))


2 print (a)

enter a no.69
69

In [ ]: 1 # IF AND ELSE STATEMENTS

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


2 b=0
3 if a%2==0:
4 print (a, "Even")
5 b=a+b
6 else :
7 print (b, "Odd")
8 b=a-b
9 print (b)

Enter a no.69
0 Odd
69

localhost:8888/notebooks/JavaMx.ipynb 1/15
7/26/23, 10:41 AM JavaMx

In [1]: 1 a= int(input("enter a no."))


2 b=0
3 if a%2 == 0:
4 print (a,"even")
5 b=b+a
6 else:
7 print (b,"odd")
8 b=b-a
9 print (b)

enter a no.5467
0 odd
-5467

In [ ]: 1 # VOTING ELIGIBLITY (are you eligible aren't u?)


2 # Create a python code using if and else statements of voting eligiblity.

In [5]: 1 x = int(input("Enter The Age "))


2 y = int(input("Enter The Age "))
3 if x>y :
4 print ("You're Eligible For Vote")
5 else :
6 print ("You're Not Elgible For Vote")

Enter The Age 67


Enter The Age 18
You're Eligible For Vote

In [ ]: 1 # PROFIT AND LOSS


2 # Create a python code to make profit and loss statements

In [ ]: 1 x= int(input("enter a no."))


2 y= int(input("enter a no."))
3 z= int(input("enter a no."))
4 a= (x*y*z/100)
5 print (a)

localhost:8888/notebooks/JavaMx.ipynb 2/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 # REPORT CARD (enter your life here)


2 # Create a python code using elif statements. Make a report card !

In [11]: 1 a=int(input("Enter Marks "))


2 if a>= 90:
3 grade = "A++"
4 elif a>= 80:
5 grade = "A+"
6 elif a>= 70:
7 grade = "A"
8 elif a>= 60:
9 grade = "B"
10 elif a>= 50:
11 grade = "C"
12 elif a>= 40:
13 grade = "D"
14 else :
15 grade = "E"
16 print ("grade = ", grade)

Enter Marks 89
grade = A+

localhost:8888/notebooks/JavaMx.ipynb 3/15
7/26/23, 10:41 AM JavaMx

In [12]: 1 print("Enter Marks Obtained in 5 Subjects: ")


2 markOne = int(input())
3 markTwo = int(input())
4 markThree = int(input())
5 markFour = int(input())
6 markFive = int(input())
7 ​
8 tot = markOne+markTwo+markThree+markFour+markFive
9 avg = tot/5
10 ​
11 if avg>=91 and avg<=100:
12 print("Your Grade is A1")
13 elif avg>=81 and avg<91:
14 print("Your Grade is A2")
15 elif avg>=71 and avg<81:
16 print("Your Grade is B1")
17 elif avg>=61 and avg<71:
18 print("Your Grade is B2")
19 elif avg>=51 and avg<61:
20 print("Your Grade is C1")
21 elif avg>=41 and avg<51:
22 print("Your Grade is C2")
23 elif avg>=33 and avg<41:
24 print("Your Grade is D")
25 elif avg>=21 and avg<33:
26 print("Your Grade is E1")
27 elif avg>=0 and avg<21:
28 print("Your Grade is E2")
29 else:
30 print("Invalid Input!")

Enter Marks Obtained in 5 Subjects:


89
79
90
95
20
Your Grade is B1

localhost:8888/notebooks/JavaMx.ipynb 4/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 # FIND THE SHORTEST AND LARGEST

In [6]: 1 a=int(input("Enter a number "))


2 b=int(input("Enter a number "))
3 c=int(input("Enter a number "))
4 if a>b and a>c :
5 print ("a is greater")
6 elif b>a and c>a :
7 print ("b is greater")
8 else :
9 print ("c is shortest")

Enter a number 09
Enter a number 80
Enter a number 70
b is greater

In [ ]: 1 x=int(input("enter a no."))


2 y=int(input("enter a no."))
3 z=int(input("enter a no."))
4 if x<y and x<z :
5 print (x, "is shortest")
6 elif y<x and z<x :
7 print (y, "is shortest")
8 else :
9 print (z, "is greatest")

In [ ]: 1 # PYTHON QUIZ (wanna copy?)

localhost:8888/notebooks/JavaMx.ipynb 5/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 print('Welcome to AskPython Quiz')


2 answer=input('Are you ready to play the Quiz ? (yes/no) :')
3 score=0
4 total_questions=3
5 ​
6 if answer.lower()=='yes':
7 answer=input('Question 1: What is your Favourite programming language?')
8 if answer.lower()=='c++':
9 score += 1
10 print('correct')
11 else:
12 print('Wrong Answer :(')
13 ​
14 ​
15 answer=input('Question 2: Do you follow any author on AskPython? ')
16 if answer.lower()=='yes':
17 score += 1
18 print('correct')
19 else:
20 print('Wrong Answer :(')
21 ​
22 answer=input('Question 3: What is the name of your favourite website for learning Python?')
23 if answer.lower()=='askpython':
24 score += 1
25 print('correct')
26 else:
27 print('Wrong Answer :(')
28 ​
29 print('Thankyou for Playing this small quiz game, you attempted',score,"questions correctly!")
30 mark=(score/total_questions)*100
31 print('Marks obtained:',mark)
32 print('BYE!')

In [ ]: 1 # DESTINATION COST AND EXPENSES

localhost:8888/notebooks/JavaMx.ipynb 6/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 destination=input("Enter a desination ")


2 no=int(input("enter no. of person "))
3 cost=0
4 final=0
5 if destination=="Goa" or destination=="goa":
6 if no>=5:
7 cost=5000
8 else:
9 cost=8000
10 elif destination=="Manali" or destination=="manali":
11 if no>=5:
12 cost=8000
13 else:
14 cost=10000
15 elif destination=="Andaman and nicobar" or destination=="andaman and nicobar":
16 if no>=5:
17 cost=10000
18 else:
19 cost=12000
20 elif destination=="Jaipur" or destination=="jaipur":
21 if no>=5:
22 cost=12000
23 else:
24 cost=15000
25 final=no*cost
26 print (final)

In [ ]: 1 # IDENTITY CARD (might work?)


2 # Create a identity card using Def identity.

localhost:8888/notebooks/JavaMx.ipynb 7/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 def create_identity_card(name, scholar_number, class_name, section):


2 pdf = FPDF(format='letter')
3 pdf.set_font('Arial', 'B', 14)
4 pdf.add_page()
5 width = 100
6 height = 60
7 x = (pdf.w - width) / 2
8 y = (pdf.h - height) / 2
9 pdf.rect(x, y, width, height)
10 pdf.set_xy(x + 5, y + 10)
11 pdf.cell(0, 10, f'Name: {name}', ln=True)
12 pdf.cell(0, 10, f'Scholar Number: {scholar_number}', ln=True)
13 pdf.cell(0, 10, f'Class: {class_name}', ln=True)
14 pdf.cell(0, 10, f'Section: {section}', ln=True)
15 pdf.output('identity_card.pdf')
16 name = input('Enter student name: ')
17 scholar_number = input('Enter scholar number: ')
18 class_name = input('Enter class name: ')
19 section = input('Enter section: ')
20 ​
21 create_identity_card(name, scholar_number, class_name, section)

In [1]: 1 print ("Hello World")

Hello World

In [ ]: 1 # CREATING THE MENU USING FOR STATEMENTS


2 # (Make sure all the codes have def integrated compiler)

localhost:8888/notebooks/JavaMx.ipynb 8/15
7/26/23, 10:41 AM JavaMx

In [4]: 1 def calculate_cost():


2 items = {"burger": 25,
3 "pizza": 100,
4 "garlic bread": 75,
5 "pasta": 90}
6 ​
7 toppings = {"burger": 15,
8 "pizza": 50,
9 "garlic bread": 15,
10 "pasta": 25}
11 ​
12 total_cost = 0
13 ​
14 print("Enter the quantity of each item you want to order:")
15 for item in items:
16 quantity = int(input(f"{item.capitalize()}: "))
17 quality = input(f"Enter quality for {item} (low/medium/high): ")
18 toppings_required = input(f"Do you want toppings for {item}? (yes/no): ")
19 ​
20 if quality == "low":
21 total_cost += items[item] * quantity
22 elif quality == "medium":
23 total_cost += (items[item] + toppings[item]) * quantity
24 elif quality == "high":
25 total_cost += (items[item] + (2 * toppings[item])) * quantity
26 ​
27 if toppings_required == "yes":
28 total_cost += toppings[item] * quantity
29 ​
30 if total_cost > 800:
31 total_cost *= 0.95
32 ​
33 print(f"Total cost is {total_cost}")
34 ​

localhost:8888/notebooks/JavaMx.ipynb 9/15
7/26/23, 10:41 AM JavaMx

In [3]: 1 def calculate_cost():


2 burger = 25
3 pizza = 100
4 garlic_bread = 75
5 pasta = 90
6 ​
7 topping_burger = 15
8 topping_pizza = 50
9 topping_garlic_bread = 15
10 topping_pasta = 25
11 ​
12 total_cost = 0
13 ​
14 print("Enter the quantity of each item you want to order:")
15 quantity_burger = int(input("Burger: "))
16 quantity_pizza = int(input("Pizza: "))
17 quantity_garlic_bread = int(input("Garlic Bread: "))
18 quantity_pasta = int(input("Pasta: "))
19 ​
20 quality = input("Enter quality (low/medium/high): ")
21 ​
22 if quality == "low":
23 total_cost += (burger * quantity_burger) + (pizza * quantity_pizza)
24 + (garlic_bread * quantity_garlic_bread) + (pasta * quantity_pasta)
25 elif quality == "medium":
26 total_cost += ((burger + topping_burger) * quantity_burger)
27 + ((pizza + topping_pizza) * quantity_pizza) + ((garlic_bread + topping_garlic_bread)
28 * quantity_garlic_bread) + ((pasta + topping_pasta) * quantity_pasta)
29 elif quality == "high":
30 total_cost += ((burger + (2 * topping_burger)) * quantity_burger)
31 + ((pizza + (2 * topping_pizza)) * quantity_pizza) + ((garlic_bread
32 + (2 * topping_garlic_bread)) * quantity_garlic_bread) + ((pasta + (2 * topping_pasta)) * quantity_pasta)
33 ​
34 if total_cost > 800:
35 total_cost *= 0.95
36 ​
37 print(f"Total cost is {total_cost}")
38 ​

localhost:8888/notebooks/JavaMx.ipynb 10/15
7/26/23, 10:41 AM JavaMx

In [2]: 1 def calculate_cost():


2 items = {"burger": 25,
3 "pizza": 100,
4 "garlic bread": 75,
5 "pasta": 90}
6 ​
7 toppings = {"burger": 15,
8 "pizza": 50,
9 "garlic bread": 15,
10 "pasta": 25}
11 ​
12 total_cost = 0
13 ​
14 print("Enter the quantity of each item you want to order:")
15 for item in items:
16 quantity = int(input(f"{item.capitalize()}: "))
17 quality = input(f"Enter quality for {item} (low/medium/high): ")
18 ​
19 if quality == "low":
20 total_cost += items[item] * quantity
21 elif quality == "medium":
22 total_cost += (items[item] + toppings[item]) * quantity
23 elif quality == "high":
24 total_cost += (items[item] + (2 * toppings[item])) * quantity
25 ​
26 if total_cost > 800:
27 total_cost *= 0.95
28 ​
29 print(f"Total cost is {total_cost}")
30 ​

In [5]: 1 print ("hello world")

hello world

In [ ]: 1 # WHILE LOOP AND STATEMENTS

localhost:8888/notebooks/JavaMx.ipynb 11/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 i=1
2 while (i<=20):
3 n=int(input("enter a no. "))
4 if (n%2==0):
5 print (n)
6 i=i+1

enter a no. 1
enter a no. 2
2
enter a no. 3
enter a no. 3
enter a no. 4
4
enter a no. 5
enter a no. 6
6
enter a no. 7
enter a no. 8
8
enter a no. 9
enter a no. 10
10
enter a no. 16
16
enter a no. 17
enter a no. 18
18
enter a no. 19
enter a no. 20
20
enter a no. 20
20

localhost:8888/notebooks/JavaMx.ipynb 12/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 i=1
2 while (1<=10):
3 n=int(input("Enter a no. "))
4 if(n%2!=0):
5 print (n)
6 i=i+1

In [ ]: 1 i=1
2 n=int(input("Enter a no. "))
3 while(i<=10):
4 t=n*i
5 print(t)
6 i=i+1

In [2]: 1 i = 1
2 n= int(input("enter a number "))
3 while (i<=10):
4 t = n * i
5 print(t)
6 i = i + 1

enter a number 100


100
200
300
400
500
600
700
800
900
1000

localhost:8888/notebooks/JavaMx.ipynb 13/15
7/26/23, 10:41 AM JavaMx

In [ ]: 1 n=int(input("enter a no. "))


2 fact = 1
3 while (n>=1):
4 fact=fact*n
5 n=n-1
6 print (fact)

In [*]: 1 sum=0
2 x=int(input("enter a no. "))
3 while (x>=0):
4 x=x//10
5 y=x%10
6 sum = sum+y
7 print (sum)

In [ ]: 1 # FOR LOOP AND STATEMENTS

In [1]: 1 x=int(input("enter a value : "))


2 for i in range (1,11,1) :
3 y=x*i
4 print(y)

enter a value : 20
20
40
60
80
100
120
140
160
180
200

localhost:8888/notebooks/JavaMx.ipynb 14/15
7/26/23, 10:41 AM JavaMx

In [1]: 1 sum=0
2 n=int(input("enter a no : "))
3 for i in range (n,1,-1):
4 x=n%10
5 n=n//10
6 sum = sum + x
7 print (sum)

enter a no : 789
24

localhost:8888/notebooks/JavaMx.ipynb 15/15

You might also like