[Python Programming Basics to Advanced]: if and if else statements (Decision Making) | Lab 05 P-2

preview_player
Показать описание
This Python programming playlist is designed to take beginners with zero programming experience to an expert level. The course covers installation, basic syntax, practical scenarios, and efficient logic building. The course material includes PDF handouts, review questions, and covers a wide range of topics, from data types to advanced functions like Lambda and Recursive functions, Generators, and JSON data parsing.

In this lesson we will use the relational operators and logical operators with if and if else statement. If and if else statements are used for decision making in programming logic.

Complete Playlist:

If you have the basic programming knowledge and interested to learn Object-Oriented Programming in Python, check out this playlist:

Lab Manual 05 can be downloaded from here:

Review Questions:
1- Write a program that will display the roots of a quadratic equation. User will enter the values of a, b and c and the program will display the roots. The value of co-efficient *a* cannot be 0 for a quadratic equation. You will assume that the user will always enter non-zero value of co-efficient *a*.
After taking input from user, find the discriminant. Then apply the IF statement on that discriminant being positive or negative since we have to find the square root of that. Use the approach similar to the square root example shown in the video.

2-The Chinese zodiac assigns animals to years in a 12 year cycle. One such cycle is as:
2000 Dragon
2001 Snake
2002 Horse
2003 Sheep
2004 Monkey
2005 Rooster
2006 Dog
2007 Pig
2008 Rat
2009 Ox
2010 Tiger
2011 Hare

The pattern repeats from there, with 2012 being another year of the dragon, and 1999 being another year of the hare.
Write a program that reads a year from the user and displays the animal associated with that year. Your program should work correctly for any year.
You should take the year input, assuming that it is positive integer, do the required calculations and then use 12 IF statements to display the associated Animal.

#PythonProgramming #python #pythontutorial
Рекомендации по теме
Комментарии
Автор

#Question1

from math import*
a, b, c=eval(input("Enter the values of 'a', 'b', 'c': "))
Disc= (b**2)-(4*a*c)
if(Disc>0):
x1=(-b+sqrt(Disc))/2*a
x2=(-b-sqrt(Disc))/2*a
print(f'The real & distinct roots are {x1} and {x2}.')
if(Disc==0):
x1=(-b+sqrt(Disc))/2*a
x2=(-b-sqrt(Disc))/2*a
print(f'The real & equal roots are {x1} and {x2}.')
if(Disc<0):
x1=complex(-b/2*a, sqrt(-Disc)/2*a)
x2=(-b/2*a, -sqrt(-Disc)/2*a)
print(f'The imaginary roots are {x1} and {x2}.')

#Question2

x=eval(input('Enter the year: '))
y=(x-2000)%12
if(y==0):
A='Dragon'
if(y==1):
A='Snake'
if(y==2):
A='Horse'
if(y==3):
A='Sheep'
if(y==4):
A='Monkey'
if(y==5):
A='Rooster'
if(y==6):
A='Dog'
if(y==7):
A='Pig'
if(y==8):
A='Rat'
if(y==9):
A='Ox'
if(y==10):
A='Tiger'
if(y==11):
A='Hare'
print(f"The Chinese Zodiac animal for the year {x} is '{A}'")

shaheerahmadkhan
Автор

def disc ( a = 1, b = 0, c = 0 ):
a = float(a)
b = float(b)
c = float(c)
dic= b**2 - 4*a*c
x = dic**1/2
if a==0: return 'not possible'
if dic==0: return 'roots of the equations are equal and real'
elif dic<0: return 'roots are imagenary and complex'
if x is int and dic>0: return 'roots are real and equal'
return 'roots are irrational and real'
a, b, c = input('Enter the value of a, b, c with spaces ').split(' ')

print(disc(a, b, c))

muhammadshess
Автор

TASK # 1:

from math import *
a, b, c=eval(input("Enter the values of a, b and c with commas :"))
disc=(b**2)-(4*a*c)
if(disc>0):
r1=(-b+sqrt(Disc))/(2*a)
r2=(-b-sqrt(Disc))/(2*a)
print(f"The function has two distinct real roots: {r1:.2f} and {r2:.2f}")

if(disc==0):
r1=r2= (-b+sqrt(Disc))/(2*a)
print(f"The function has equal real roots: {r1:.2f} and {r2:.2f}")

else:
r1=complex((-b/(2*a)), sqrt(-disc)/(2*a))
r2=complex((-b/(2*a)), -sqrt(-disc)/(2*a))
print(f"The function has two complex roots: {r1:.2f} and {r2:.2f}")


TASK # 2:

Year=eval(input('Enter A Year :'))
x=(Year-2000)%12
if (x==0):
Animal='Dragon'
if (x==1):
Animal='Snake'
if (x==2):
Animal='Horse'
if (x==3):
Animal='Sheep'
if (x==4):
Animal='Monkey'
if (x==5):
Animal='Rooster'
if (x==6):
Animal='Dog'
if (x==7):
Animal='Pig'
if (x==8):
Animal='Rat'
if (x==9):
Animal='Ox'
if (x==10):
Animal='Tiger'
if (x==11):
Animal='Hare'
print(f'The Chinese Zodiac sign of year {Year} is {Animal}.')

zoniseithzoniseith
Автор

Answer 1 :
from math import*
a, b, c=eval(input("Enter value of a, b, c : "))
disc=(b**2)-(4*a*c)
if((disc>=0) and (a>0 or a<0)):
q, r=(-b+(sqrt(disc)))/(2*a), (-b-(sqrt(disc)))/(2*a)
print(q, r)
if((disc<=0) and (a>0 or a<0)):
q, r=(-b+(sqrt(-disc)))/(2*a), (-b-(sqrt(-disc)))/(2*a)
print(q, r)

abdurrehmansarwar
Автор

1-
from math import sqrt
a, b, c=eval(input("Enter the values of a, b, c of a quadratic equation"))
d=(b**2)-4*a*c
if(d>=0):
print(f"Your roots are {(-b+sqrt(d))/2*a} and {(-b-sqrt(d))/2*a}")
else:
s=complex(0, sqrt(-d))
print(f"Your roots are {(-b+s)/2*a} and {(-b-s)/2*a}")

fourcloversan
Автор

Task#1:
from math import*
a, b, c=eval(input('Enter the cofficients(a, b, c):'))
disc=b**2-(4*a*c)
if(disc>0):
print(f'The roots are{(-b+sqrt(disc))/(2*a)} and {(-b-sqrt(disc))/(2*a)}')
if(disc==0):
print(f'the repeated roots are{-b/(2*a)}, {-b/(2*a)}')
if(disc<0):
d=disc
d=complex(0, sqrt(-d))
print(f'The complex conjugate roots are{(-b+d)/(2*a)}, {(-b-d)/(2*a)}')





Task#2:
x=int(input('Enter year:'))
y=x%12
if(y==8):
print('Dragon')
if(y==9):
print('Snake')
if(y==10):
print('Horse')
if(y==11):
print('Sheep')
if(y==0):
print('monkey')
if(y==1):
print('Rooster')
if(y==2):
print('Dog')
if(y==3):
print('Pig')
if(y==4):
print('Rat')
if(y==5):
print('Ox')
if(y==6):
print('Tiger')
if(y==7):
print('Hare')

abdulrehmankhalid
Автор

Q1=
a, b, c=eval(input('enter the values of a, b, c:'))
d=b**2 -4*a*c
from math import sqrt
if(d<0 and a!=0):
D=complex(0, sqrt(-d))
s1=(-b+D)/2*a
s2=(-b-D)/2*a
print(f'There are two roots of quadratic equation {s1:.2f}and {s2:.2f}')

if(a!=0 and d>=0):
g=sqrt(d)
s1=(-b+g)/2*a
s2=(-b-g)/2*a
print(f'There are two roots of quadratic equation {s1:.2f}and {s2:.2f}')
else:
print('The value of a should not be 0')

danishali
Автор

1)

from math import *
x, y, z=eval(input("Enter the values of x, y and z with commas :"))
disc=(y**2)-(4*x*z)
if(disc>0):
r1=(-y+sqrt(Disc))/(2*x)
r2=(-y-sqrt(Disc))/(2*x)
print(f"The function has two distinct real roots: {r1:.2f} and {r2:.2f}")

if(disc==0):
r1=r2= (-y+sqrt(Disc))/(2*x)
print(f"The function has equal real roots: {r1:.2f} and {r2:.2f}")

else:
r1=complex((-y/(2*x)), sqrt(-disc)/(2*x))
r2=complex((-y/(2*x)), -sqrt(-disc)/(2*x))
print(f"The function has two complex roots: {r1:.2f} and {r2:.2f}")


2)

Year=eval(input('Enter A Year :'))
m=(Year-2000)%12
if (m==0):
Animal='Dragon'
if (m==1):
Animal='Snake'
if (m==2):
Animal='Horse'
if (m==3):
Animal='Sheep'
if (m==4):
Animal='Monkey'
if (m==5):
Animal='Rooster'
if (m==6):
Animal='Dog'
if (m==7):
Animal='Pig'
if (m==8):
Animal='Rat'
if (m==9):
Animal='Ox'
if (m==10):
Animal='Tiger'
if (m==11):
Animal='Hare'
print(f'The Chinese Zodiac sign of year {Year} is {Animal}.')

haris
Автор

Task#1
from math import sqrt
a, b, c=eval(input('Enter the values of a, b, c of quadratic equation:'))
s=(b**2)-(4*a*c)
if(s>0):
q1=(-b+sqrt(s))/2*a
q2=(-b-sqrt(s))/2*a
print(f"The roots of the quaratic equal are real {q1} and {q2}")
if(s==0):
q1=(-b+sqrt(s))/2*a
q2=(-b-sqrt(s))/2*a
print(f"The roots of the quaratic equal are equal {q1} and {q2}")
if(s<0):
w1=complex(-b/2*a, sqrt(abs(s))/2*a)
w2=complex(-b/2*a, -sqrt(abs(s))/2*a)
print(f"The roots of the quadratic eqaution are imaginary {w1} and {w2}")
print(s)

Task#2
y=eval(input('Enter the year:'))
s=(y-2000)%12
if(s==0):
x='Dragon'
if(s==1):
x='Snake'
if(s==2):
x='Horse'
if(s==3):
x='Sheep'
if(s==4):
x='Monkey'
if(s==5):
x='Rooster'
if(s==6):
x='Dog'
if(s==7):
x='Pig'
if(s==8):
x='Rat'
if(s==9):
x='Ox'
if(s==10):
x='Tiger'
if(s==11):
x='Hare'
print(f'The Chinese zodiac sign for the year {y} is {x}')

saifullahafzal
Автор

Q1)
from math import sqrt
a=eval(input("Enter the first value:"))
b=eval(input("Enter the second value:"))
c=eval(input("Enter the third value:"))
Disc=(b**2)-(4*a*c)
if (Disc>0):
x1=(-b+sqrt(Disc))/(2*a)
x2=(-b-sqrt(Disc))/(2*a)
print(f"The equation has real and distinct roots {x1} and {x2}")
if (Disc==0):
x1=(-b+sqrt(Disc))/(2*a)
x2=(-b-sqrt(Disc))/(2*a)
print(f"The equation has real and equal roots {x1} and {x2}")
if (Disc<0):
x1= complex((-b/(2*a)), sqrt(-Disc)/(2*a))
x2= complex((-b/(2*a)), -sqrt(-Disc)/(2*a))
print(f"The equation has complex roots {x1} and {x2}")

Q2)
Year=int(input("Enter the Year:"))
A=(Year-2000)%12
if A==0:
animal= "Dragon"
if A==1:
animal= "Snake"
if A==2:
animal= "Horse"
if A==3:
animal= "Sheep"
if A==4:
animal= "Monkey"
if A==5:
animal= "Rooster"
if A==6:
animal= "Dog"
if A==7:
animal= "Pig"
if A==8:
animal= "Rat"
if A==9:
animal= "Ox"
if A==10:
animal= "Tiger"
if A==11:
animal= "Hare"
print(f"The Chinese zodiac sign of year {Year} is {animal}.")

yusrakashif
Автор

Q1:-

from math import *
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
c=int(input("Enter the value of c:"))

Disc=b*b-4*a*c

if Disc>=0:
x1=(-b+sqrt(Disc))/(2*a)
x2=(-b-sqrt(Disc))/(2*a)
else:
x1=(-b+complex(0, sqrt(-Disc)))/(2*a)
x2=(-b-complex(0, sqrt(-Disc)))/(2*a)

print(f"The roots of this quadratic equation are {x1} and {x2}")


Q2:-

x=eval(input("Enter:"))
y=(x-2000)%12
if (y==0):
print("Dragon")
if (y==1):
print("Snake")
if (y==2):
print("Horse")
if (y==3):
print("Sheep")
if (y==4):
print("Monkey")
if (y==5):
print("Rooster")
if (y==6):
print("Dog")
if (y==7):
print("Pig")
if (y==8):
print("Rat")
if (y==9):
print("Ox")
if (y==10):
print("Tiger")
if (y==11):
print("Hare")

MuhammadAhmad-dshu
Автор

Task 1)
from math import *
import cmath
a=eval(input('Enter the first number (must not be 0):'))
b=eval(input('Enter the second number:'))
c=eval(input('Enter the third number:'))
d=b**2-4*a*c
if (a==0):
print('a must not be 0')
if (d>0):
x=(-b+sqrt(d))/2*a
y=(-b-sqrt(d))/2*a
print(f"Roots {x, y} are real and distinct.")
if (d==0):
x=y=(-b+sqrt(d))/2*a
print(f"Roots {x, y} are equal and real.")
if (d<0):
d=complex(0, sqrt(-d))
x=(-b+d)/2*a
y=(-b-d)/2*a
print(f"Roots {x, y} are complex and imaginary.")


Task 2)
Year=int(input("Enter a year:"))
S=((Year-2000)%12)
if S==0:
animal="Dragon"
if S==1:
animal="Snake"
if S==2:
animal="Horse"
if S==3:
animal="Sheep"
if S==4:
animal="Monkey"
if S==5:
animal="Rooster"
if S==6:
animal="Dog"
if S==7:
animal="Pig"
if S==8:
animal="Rat"
if S==9:
animal="Ox"
if S==10:
animal="Tiger"
if S==11:
animal="Hare"
print(f'The Chinese Zodiac symbol for the year {Year} is {animal}.')

waleedraza
Автор

Question#1
from math import *
a, b, c=eval(input('Enter the three coefficients of quadratic equation= '))
if(a==0):
print('coefficient a should not be zero.')
d=(b**2)-4*(a*c)
if(d>=0 and a!=0):
print(f'root of the quadratic equation are {sqrt(d)}')
if(d<0 and a!=0):
x=abs(d)
print(f'root of the quadratic equation are {sqrt(x)}')
Question#2
x=eval(input('enter the year= '))
y=x%12
if(y==0):
print('Assigned animal to the year is Monkey.')
if(y==1):
print('Assigned animal to the year is Rooster.')
if(y==2):
print('Assigned animal to the year is Dog.')
if(y==3):
print('Assigned animal to the year is Pig.')
if(y==4):
print('Assigned animal to the year is Rat.')
if(y==5):
print('Assigned animal to the year is Ox.')
if(y==6):
print('Assigned animal to the year is Tiger.')
if(y==7):
print('Assigned animal to the year is Hare.')
if(y==8):
print('Assigned animal to the year is Dragon.')
if(y==9):
print('Assigned animal to the year is Snake.')
if(y==10):
print('Assigned animal to the year is Horse.')
if(y==11):
print('Assigned animal to the year is Sheep.')

SafiUllah-kgku
Автор

Question-1a=eval(input("Enter the 1st value: "))b=eval(input("Enter the 2nd value: "))c=eval(input("Enter the 3rd value: "))if (Disc>0):
print(f'The equation has real and distinct roots:{x1}, {x2}')
if print(f'The equation has real and equal roots:{x1}, {x2}')
else:x1= complex((-b/(2*a)), sqrt(-Disc)/(2*a))
x2= complex((-b/(2*a)), -sqrt(-Disc)/(2*a)) print(f'The equation has complex roots:{x1}, {x2}')
Q2)=Year=int(input("Enter the Year:"))A=(Year-2000)%12if A==0:animal= "Dragon"if A==1: animal= "Snake"if A==2:
animal= "Horse"if A==3:animal= "Sheep"if A==4:animal= "Monkey"
if A==5:animal= "Rooster"
if A==6: animal= "Dog"
if A==7:
animal= "Pig"if A==8:animal= "Rat"if A==9:animal= "Ox"
if A==10:animal= "Tiger"if A==11:animal= "Hare"
print(f"The Chinese zodiac sign of year {Year} is {animal}."

mukarmarashid
Автор

Question-01
from math import sqrt
a=eval(input("Enter the co-efficient of variable with power 2:"))
b=eval(input("Enter the co-efficient of variable with power 1:"))
c=eval(input("Enter the constant value:"))
Disc=(b**2)-(4*a*c)
if (Disc>0):
x1=(-b+sqrt(Disc))/(2*a)
x2=(-b-sqrt(Disc))/(2*a)
print(f"The equation has real and distinct roots:{x1}, {x2}")
if (Disc==0):
x1=(-b+sqrt(Disc))/(2*a)
x2=(-b-sqrt(Disc))/(2*a)
print(f"The equation has real and identical roots:{x1}, {x2}")
else:
x1= complex((-b/(2*a)), sqrt(-Disc)/(2*a))
x2= complex((-b/(2*a)), -sqrt(-Disc)/(2*a))
print(f"The equation has complex roots:{x1}, {x2}")
Question-02
Y=int(input("Enter the Year:"))
A=(Y-2000)%12
if A==0:
animal= "Dragon"
if A==1:
animal= "Snake"
if A==2:
animal= "Horse"
if A==3:
animal= "Sheep"
if A==4:
animal= "Monkey"
if A==5:
animal= "Rooster"
if A==6:
animal= "Dog"
if A==7:
animal= "Pig"
if A==8:
animal= "Rat"
if A==9:
animal= "Ox"
if A==10:
animal= "Tiger"
if A==11:
animal= "Hare"
print(f"The Chinese zodiac sign of year {Y} is {animal}.")

nukhbaiqbal
Автор

Que # 1):

from math import sqrt
a=eval(input("Enter value of a: "))
b=eval(input("Enter value of b: "))
c=eval(input("Enter value of c: "))
D=(b**2)-(4*a*c)
if(D>0):
x=(-b+sqrt(D))/(2*a)
y=(-b-sqrt(D))/(2*a)
print(f"The function has two distinct real roots: {x} and {y}")
if(D==0):
x=(-b+sqrt(D))/(2*a)
y=(-b-sqrt(D))/(2*a)
print(f"The function has repeated real roots: {x} and {y}")
if(D<0):
x=complex(-b/(2*a), sqrt(-D)/(2*a))
y=complex(-b/(2*a), -sqrt(-D)/(2*a))
print(f"The function has two complex (conjugate) roots: {x} and {y}")



Que # 2):

a=eval(input("Enter any Year: "))
b=a%12
if(b==0):
print(f"The Chinese zodiac sign for {a} is Monkey.")
if(b==1):
print(f"The Chinese zodiac sign for {a} is Rooster.")
if(b==2):
print(f"The Chinese zodiac sign for {a} is Dog.")
if(b==3):
print(f"The Chinese zodiac sign for {a} is Pig.")
if(b==4):
print(f"The Chinese zodiac sign for {a} is Rat.")
if(b==5):
print(f"The Chinese zodiac sign for {a} is Ox.")
if(b==6):
print(f"The Chinese zodiac sign for {a} is Tiger.")
if(b==7):
print(f"The Chinese zodiac sign for {a} is Hare.")
if(b==8):
print(f"The Chinese zodiac sign for {a} is Dragon.")
if(b==9):
print(f"The Chinese zodiac sign for {a} is Snake.")
if(b==10):
print(f"The Chinese zodiac sign for {a} is Horse.")
if(b==11):
print(f"The Chinese zodiac sign for {a} is Sheep.")

ahmadlatif
Автор

Q1:
from math import sqrt
a, b, c=eval(input("enter 3 digits:"))
D=(b**2)-(4*a*c)
if(D==0 and a>0):
root1=root2=-b/2*a
if(D>0 and a>0):
root1=(-b+sqrt(D))/(2*a)
root2=(-b-sqrt(D))/(2*a)
print(f'the roots are {root1} and {root2}')
if(D<0 and a>0):
root1=complex((-b/(2*a)), sqrt(abs(-D))/(2*a))
root2=complex((-b/(2*a)), -sqrt(abs(-D))/(2*a))
print(f'the roots of the quadratic equation are {a}x**2+{b}**x+{c} is {root1} and {root2}')
Q2:
x=eval(input("Enter a Year:"))
y=(x-2000)%12
if(y==0):
y='dragon'
if(y==1):
y='snake'
if(y==2):
y='horse'
if(y==3):
y='sheep'
if(y==4):
y='monkey'
if(y==5):
y='rooster'
if(y==6):
y='dog'
if(y==7):
y='pig'
if(y==8):
y='rat'
if(y==9):
y='Ox'
if(y==10):
y='tiger'
if(y==11):
y='hare'
print(f'The zodiac sign of year {x} is {y}')

shahwarsadaqat
Автор

Ans # 1:

from math import *
a, b, c=eval(input("Enter the values of a, b and c with commas :"))
disc=(b**2)-(4*a*c)
if(disc>0):
r1=(-b+sqrt(Disc))/(2*a)
r2=(-b-sqrt(Disc))/(2*a)
print(f"The function has two distinct real roots: {r1:.2f} and {r2:.2f}")

if(disc==0):
r1=r2= (-b+sqrt(Disc))/(2*a)
print(f"The function has equal real roots: {r1:.2f} and {r2:.2f}")

else:
r1=complex((-b/(2*a)), sqrt(-disc)/(2*a))
r2=complex((-b/(2*a)), -sqrt(-disc)/(2*a))
print(f"The function has two complex roots: {r1:.2f} and {r2:.2f}")


Ans # 2:

Year=eval(input('Enter A Year :'))
x=(Year-2000)%12
if (x==0):
Animal='Dragon'
if (x==1):
Animal='Snake'
if (x==2):
Animal='Horse'
if (x==3):
Animal='Sheep'
if (x==4):
Animal='Monkey'
if (x==5):
Animal='Rooster'
if (x==6):
Animal='Dog'
if (x==7):
Animal='Pig'
if (x==8):
Animal='Rat'
if (x==9):
Animal='Ox'
if (x==10):
Animal='Tiger'
if (x==11):
Animal='Hare'
print(f'The Chinese Zodiac sign of year {Year} is {Animal}.')

hamzaubaid
Автор

Question # 1
import math
a=eval(input("Insert value of a: "))
b=eval(input("Insert value of b: "))
c=eval(input("Insert value of c: "))
D=(b**2)-(4*a*c)


if D>=0:

x1=(-b+math.sqrt(D))/2*a
x2=(-b-math.sqrt(D))/2*a
else:
x1= complex((-b/(2*a)), math.sqrt(-D)/(2*a))
x2= complex((-b/(2*a)), -math.sqrt(-D)/(2*a))

if D>0:
print(f"The function has two distinct real roots: {x1} and {x2}")
if D==0:
print(f"The function has one double root:{x1}")
else:
print(f"The function has two complex (conjugate) roots: {x1} and {x2}")



Question # 2

x=eval(input("Enter the Year:"))
if x%100==(00 or 12 or 24 or 36 or 48 or 60 or 72 or 84 or 96):
sign = "Dragon"
if x%100==(1 or 13 or 25 or 37 or 49 or 61 or 73 or 85 or 97):
sign = "Snake"
if x%100==(2 or 14 or 26 or 38 or 50 or 62 or 74 or 86 or 98):
sign = "Horse"
if x%100==(3 or 15 or 27 or 39 or 51 or 63 or 75 or 87 or 99):
sign = "Sheep)"
if x%100==(4 or 16 or 28 or 40 or 52 or 64 or 76 or 88):
sign = "Monkey"
if x%100==(5 or 17 or 29 or 41 or 53 or 65 or 77 or 89):
sign = "Rooster"
if x%100==(6 or 18 or 30 or 42 or 54 or 66 or 78 or 90):
sign = "Dog"
if x%100==(7 or 19 or 31 or 43 or 55 or 67 or 79 or 91):
sign = "Pig"
if x%100==(8 or 20 or 32 or 44 or 56 or 68 or 80 or 92):
sign = "Rat"
if x%100==(9 or 21 or 33 or 45 or 57 or 69 or 81 or 93):
sign = "Ox"
if x%100==(10 or 22 or 34 or 46 or 58 or 70 or 82 or 94):
sign = "Tiger"
if x%100==(11 or 23 or 35 or 47 or 59 or 71 or 83 or 95):
sign = 'Hare'
print(f"The Chinese zodiac sign for {x} is {sign}.")

MuhammadTalha-xmul
Автор

Question#1:

from math import sqrt
a, b, c=eval(input("Enter the coeficient (a, b, c) of Quadratic Equation ax^2+bx+c=0: "))
D=(b**2)-(4*a*c)
if (D==0):
r1=r2=-b/(2*a)
if (D>0):
r1=-b+sqrt(D)/(2*a)
r2=-b-sqrt(D)/(2*a)
if (D<0):
r1=complex(-b/(2*a), sqrt(abs(D))/(2*a))
r2=complex(-b/(2*a), -sqrt(abs(D))/(2*a))
print(f"Roots of the given Quadratic Equation are ({r1}, {r2})")


Question#2:

yr=int(input("Enter the year: "))

print(f"Dragon is the animal assosiated with the year, {yr}")

print(f"Snake is the animal assosiated with the year, {yr}")

print(f"Horse is the animal assosiated with the year, {yr}")

print(f"Sheep is the animal assosiated with the year, {yr}")

print(f"Monkey is the animal assosiated with the year, {yr}")

print(f"Rooster is the animal assosiated with the year, {yr}")

print(f"Dog is the animal assosiated with the year, {yr}")

print(f"Pig is the animal assosiated with the year, {yr}")

print(f"Rat is the animal assosiated with the year, {yr}")

print(f"Ox is the animal assosiated with the year, {yr}")

print(f"Tiger is the animal assosiated with the year, {yr}")

print(f"Hare is the animal assosiated with the year, {yr}")

amaanmajid