Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python code 2

The document contains multiple Python scripts that demonstrate various programming concepts such as comparing numbers, determining even or odd, finding the largest of three numbers, and calculating student grades based on marks. Each script includes user input and outputs results based on the conditions defined in the code. The examples also show how to handle triangle properties and roots of quadratic equations.

Uploaded by

sayoojps369
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python code 2

The document contains multiple Python scripts that demonstrate various programming concepts such as comparing numbers, determining even or odd, finding the largest of three numbers, and calculating student grades based on marks. Each script includes user input and outputs results based on the conditions defined in the code. The examples also show how to handle triangle properties and roots of quadratic equations.

Uploaded by

sayoojps369
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Welcome hello.py X E Microsoft Edge.

lnk

+ hello.py > ...


a=int(input ("Enter a number:") )
2 b=int(input ("Enter a number:") )
if a>b:
4 print (a, "is greater than", b)
else:
6 print (b, "is greater than", a)
7

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python + 0 a X


PS C:\Users\Aditya\OneDrive\Desktop> & C: /Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter a number:10
Enter a number:1
10 is greater than 1
PS C:\Users \Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3. 11. exe c: /Users/Aditya/OneDr
ive/Desktop/hello. py
Enter a number:1
Enter a number:10
10 is greater than 1
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X E Microsoft Edge.nk

hello.py> ...
1 a=int (input ("Enter a number:"))
2 if (a%2) ==0:
3 print (a, "is even")
4 else:
5 print(a, "is odd")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python AX

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter a number;4
4 is even
PS C:\Users \Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello.py
Enter a number:3
3 is odd
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py F Microsoft Edge.lnk
hello.py >...
a=int (input("Enter a number:"))
b=int (input ("Enter a number:") )
c=int (input("Enter a number:"))
if a>b and a>c:
5 print (a,"is the largest")
elif b>c and b>a:

print (b,"is the largest")


else:
print(C, "is the largest")
10

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t 0 a X

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter a number:3
Enter a number:2
Enter a number:1
3 is the largest
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Enter a number:1
Enter a number:3
Enter a number:2
3 is the largest
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X Microsoft Edge. Ink
hello.py ..
1 i=int(input("Enter the internal marks out of 50:"))
2 e=int (input("Enter the external marks out of 100:"))
3 s=((ite) /150) *100
4 if s>=45:
5 print ("The student has passed in this particular subject")
6 else:
7 print ("The student has failed in this particular subject")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter the internal marks out of 50:34
Enter the external marks out of 100:80
The student has passed in this particular subject
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the internal marks out of 5e:40
Enter the external marks out of 100:3
The student has failed in this particular subject
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py Microsoft Edge.Ink
hello.py >..
1 n=int (input ("Enter the number: "))
2 if n==0:
3 print (" The number is zero")
4 elif n>0:
5 print (n, "is a positive number")
6 elif n<e:
7 print (n, "is a negative number")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python + m . aX

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter the number: 0
The number is zero
PS C:\Users\Aditya\OneDrive\Desktop> & C: /Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users//Aditya/0neDr
ive/Desktop/hello . py
Enter the number:1
1 is a positive number
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users /Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the number:-1
-1 is a negative number
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome + hello.py X Microsoft Edge.Ink
hello.py >.
1 #let the equation be ax^2+bx+tc=0
2
from math import sqrt
a=float (input ("Enter the number: "))
b=float (input ("Enter the number: "))
6 c=float(input ("Enter the number:"))
7 d=((b*b) - (4ta*c) )
8 d1=sqrt (d)
if d>e:
1 x1=((-b) +d1) / (2*a)
11 x2=((-b) -d1) / (2+a)
12 print("The real and different roots are", x1, "and", x2)
13 elif d==0:
14 x=(-b)/(2*a)
15 print("The real and same roots are",x)
16 else:
17 r=(-b) /(2*a)
18 im=d1/ (2*a)
19 print ("The complex and different roots are:")
PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users\Aditya\OneDrive\Desktop> & C: /Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter the number:1
Enter the number: -2
Enter the number: -15
The real and different roots are 5.0 and -3.0
PS C:\Users\Aditya\OneDrive\Desktop> &C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11.exe c:/Users /Aditya/OneDr
ive/Desktop/hello. py
Enter the number:8
Enter the number:2
Enter the number:-15
The real and different roots are 1.25 and -1.5
PS C:\Users\Aditya \OneDrive\Desktop>
Welcome " hello.py X E Microsoft Edge.Ink
hello.py >...
1 a=int (input("Enter side 1:"))
2 b=int (input ("Enter side 2:"))
3 c=int (input("Enter side 3:"))
4 if (a+b) >c:
5 if (c+b) >a:
6 if (a+c) >b:
7 print("The sides form a triangle")
8 else:
9 print ("The sides do not form a triangle")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter side 1:3
Enter side 2:4
Enter side 3:5
The sides form a triangle
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter side 1:e
Enter side 2:1
Enter side 3:3
The sides do not form a triangle
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome + hello.py X E Microsoft Edqe.Ink

hello.py.
a=int (input ("Enter side 1:"))
2 b=int (input ("Enter side 2:"))
c=int(input ("Enter side 3:"))
4 if a=b==c:
print("It is an equilateral triangle")
6 elif (a==b) or (b==c) or (a==c):
7 print ("It is an isosceles triangle")
elif a!=b!=c:
print ("It is a scalene triangle")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t 0 X

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowSApps/python3.11. exe c:/Users/Aditya/OneDr


ive/Desktop/hello. py
Enter side 1:1
Enter side 2:1
Enter side 3:3
It is an isosceles triangle
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Enter side 1:1
Enter side 2:1
Enter side 3:1
It is an equilateral triangle
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Welcome hello.py X Microsoft Edge.Ink
hello.py ...
1 from math import sqrt
2 x1=int (input("Enter x coordinate:"))
3 yl=int (input ("Enter y coordinate:"))
x2=int (input ("Enter x coordinate:"))
y2=int (input("Enter y coordinate:"))
6 X3=int (input("Enter x coordinate:") )
7 y3=int (input ("Enter y coordinate :"))
3
dl=sqrt (( (x2-x1) **2) +((y2 -y1) **2) )
d2=sqrt (((x3-x2) **2) +( (y3-y2) **2))
10 d3=sqrt(((X3-x1) **2) +((y3-y1) +*2))
11 if dl==d2==d3 :
12 print ("It is an equilateral triangle")
13 elif (d1==d2) or (d2==d3) or (d1==d3) :
14 print ("It is an isosceles triangle")
15 elif d1|=d2 | =d3:
16 print ("It is a scalene triangle")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t 0 a X


PS C:\Users \Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Enter x coordinate:6
Enter y coordinate:4
Enter x coordinate:5
Enter y coordinate:-2
Enter x coordinate:7
Enter y coordinate:-2
It is an isosceles triangle
PS C:\Users\Aditya\OneDrive\Desktop>
X
Welcome + hello.py X Microsoft Edge.Ink
" hello.py >
n=int (input ("Enter the marks out of 100:"))
2 if n>=90:
print ("The grade is 0")
4 elif n>=85 and n<90:
print ("The grade is A+")
elif n>=80 and n<85:
7 print("The grade is A")
8 elif n>70 and n<80:
print ("The grade is B+")
1 elif n>=60 and n<70:
11 print ("The grade is B")
12 elif n>=50 and n<60:
13 print("The grade is C+")
14 elif n>=45 and n<50:
15 print ("The grade is P")
16 elif n<45:
17 print ("The grade is F")
18

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t 0 X


PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello .py
Enter the marks out of 100:5
The grade is C+
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the marks out of 100:100
The grade is 0
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the marks out of 100:3e
The grade is F
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X E Microsoft Edge.lnk

hello.py >...
1 a=input ("Do you like python?: ")
2 if a=="Yes" or a=="yes" or a=="YES":
3 print ("That's great !")
1 elif a="No" or a==" no" or a=="NO":
print ("That is disappointing")
6 else:
print ("Enter yes/no")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t D a X


PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Do you 1ike python?: YES
That's great!
PS C:\Users\Aditya\OneDrive\Desktop> &C: /Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Do you like python?: no
That is disappointing
PS C:\Users \Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local /Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hell0. py
Do you like python?: why
Enter yes/no
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X E Microsoft Edge.Ink
" hello.py>...
y=int (input ("Enter the year:") )
2 if (y%400) ==0) and ((y%190) ==0) :
3 print (y, "is a leap year")
elif ((y%4) ==0) and ((y%190) I=e) :
5 print (y, "is a leap year")
else:
7 print (y, "is not aleap year")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORIS Python t a X

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr


ive/Desktop/hello . py
Enter the year:2000
2000 is a leap year
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the year:1995
1995 is not a leap year
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X
Microsoft Edge.Ink
hello.py >..
ni=int(input("Enter the x coordinate:"))
2 n2=int(input ("Enter the y coordinate :"))
3 if n1>0 and n2>e:
4 print (n1, n2, "lies in the first quadrant")
5 elif n1<0 and n2<0:

print (n1,n2, "lies in the third quadrant")


7 elif n1>0:
if n2<0:

print (nl, n2, " lies in the fourth quadrant")


10 elif n2>0:
11 if n1<O:
12 print (n1, n2,, " 1ies in the second quadrant")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS Python t 0 a X


PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/ AppData/Local/Microsoft/WindowSApps/python3.11. exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Enter the x coordinate:1
Enter the cOordinate:3
1 3 lies in the first quadrant
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/0neDr
ive/Desktop/hello . py
Enter the x coordinate:-2
Enter the y coordinate:3
-2 3 lies in the second quadrant
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello . py
Welcome hello.py X E Microsoft Edge. Ink

" hello.py >...


1 n=float (input ("Enter the number: "))
if n<1:
3 p=n*(-1)
print ("The absolute value is",p)
5 else:
6 print (n, "is the absolute value of",n)
7

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS ] Python + A X

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11. exe c:/Users/ Aditya/0neDr


ive/Desktop/hello. py
Enter the number:-8.9
The absolute value is 8.9
PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/Local/Microsoft/WindowSApps/python3.11.exe c:/Users/Aditya/OneDr
ive/Desktop/hello. py
Enter the number:8.9
8.9 is the absolute value of 8.9
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py X E Microsoft Edge.nk

hello.py >.
1 a=int (input ("Enter the side 1 of a triangle: "))
2 b=int (input ("Enter the side 2 of a triangle : ") )
3 c=int (input ("Enter the side 3 of a triangle: ") )
4 if (((a*a) +(b*b) )== (c*c)) or (( (b*b)+(ctc) ) ==(a*a) ) or (((a*a) +(c*c) )==(b*b) ):
print("It is a right angled triangle")
6 else:
print ("It is not a right angled triangle")
8

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users\Aditya\OneDrive\Desktop> & C:/Users/Aditya/AppData/ Local/Microsoft/WindowsApps/python3.11. exe c:/Users/Aditya/0neDr


ive/Desktop/hello . py
Enter the side 1 of a triangle:3
Enter the side 2 of a triangle:4
Enter the side 3 of a triangle:5
It is a right angled triangle
PS C:\Users\Aditya\OneDrive\Desktop>
Welcome hello.py Microsoft Edge.Ink
" hello.py ...
1 from math import sqrt
2 X1=int (input ("Enter x coordinate:"))
yl=int (input ("Enter y coordinate:"))
X2=int (input("Enter x coordinate:"))
5
y2=int (input("Enter y coordinate:"))
6 X3=int (input ("Enter x coordinate:"))
7 y3=int (input ("Enter y coordinate:") )
8 a=sqrt(( (x2-x1) **2)+( (y2-y1)**2))
9 b=sqrt( ((x3-x2) **2)+((y3-y2) **2) )
1 c=sqrt( ((x3-x1) **2)+( (y3-y1)**2) )
11 if (a+b) >c:
12 if (c+b) >a:
13 if (a+c) >b:
14 print("The sides form a triangle")
15 else:
16 print ("The sides do not form a triangle")

PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users \Aditya\OneDrive\Desktop> &C:/Users/Aditya/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/Users/Aditya/OneDr


ive/Desktop/hello. py
Enter X coordinate:3
Enter y coordinate:4
Enter x coordinate:1
Enter y coordinate:2
Enter x coordinate:5
Enter y coordinate:7
The sides form a triangle
PS C:\Users\Aditya\OneDrive\Desktop>

You might also like