Page 268 - COPA VOL II of II - TP -Punjabi
P. 268
print(“The roots are real and distinct.”) Fig 1
r1 = (-b+(math.sqrt(d)))/(2*a)
r2 = (-b-(math.sqrt(d)))/(2*a)
print(“The root1 is: “, r1)
print(“The root2 is: “, r2)
else:
print(“The roots are imaginary.”)
rp = -b/(2*a)
ip = math.sqrt(-d)/(2*a)
print(“The root1 is: “, rp, “+ i”,ip)
print(“The root2 is: “, rp, “- i”,ip)
else: import datetime
print(“Not a quadratic equation.”) print(“Generate a random integer between 0 and 6:”)
Output: print(random.randrange(5))
print(“Generate random i nteger between 5 and 10,
excluding 10:”)
print(random.randrange(start=5, stop=10))
The roots are imaginary. print(“Generate random integer between 0 and 10, with
a step of 3:”)
The r oot1 is: - 0.5909090909090909 + i
1.033928558684211 print(random.randrange(start=0, stop=10, step=3))
The r oot2 is: - 0.5909090909090909 - i print(“\nRandom date between two dates:”)
1.033928558684211 start_dt = datetime.date(2019, 2, 1)
ਉਦਾਹਰਨ 4 : ਪਾਇਥਨ ਪਰਰੋਗਰਾਮ ਟਰਟਲ ਦੀ ਿਰਤੋਂ ਕਰਕੇ ਿਰਗਾਂ ਦਾ ਇੱਕ end_dt = datetime.date(2019, 3, 1)
ਚੱਕਰ ਖਭੱਚਣ ਲਈ time_between_dates = end_dt - start_dt
import turtle days_between_dates = time_between_dates.days
x=turtle.Turtle() random_number_of_days = r andom.randrange(days_
between_dates)
def square(angle):
random_date = s tart_dt + datetime.
x.forward(100)
timedelta(days=random_number_of_days)
x.right(angle) print(random_date)
x.forward(100) Output:
x.right(angle) Generate a random integer between 0 and 6:
x.forward(100) 1
x.right(angle) Generate random integer between 5 and 10, excluding
x.forward(100) 10:
x.right(angle+10) 6
for i in range(36): Generate random integer between 0 and 10, with a step
of 3:
square(90)
0
Output: (Fig 1)
ਆਉਟਪੁੱਟ : (ਚਭੱਤਰ 1) Random date between two dates:
2019-02-26
ਉਦਾਹਰਨ 5 : 0 ਅਤੇ 6 ਦੇ ਿਭਚਕਾਰ ਇੱਕ ਬੇਤਰਤੀਬ ਪੂਰਨ ਅੰਕ ਬਣਾਉਣ
ਲਈ ਇੱਕ ਪਾਈਥਨ ਪਰਰੋਗਰਾਮ ਲਭਖੋ - 6 ਨੂੰ ਛੱਡ ਕੇ, 5 ਅਤੇ 10 ਦੇ ਿਭਚਕਾਰ
ਬੇਤਰਤੀਬ ਪੂਰਨ ਅੰਕ - 10 ਨੂੰ ਛੱਡ ਕੇ, 0 ਅਤੇ 10 ਦੇ ਿਭਚਕਾਰ ਬੇਤਰਤੀਬ ਪੂਰਨ
ਅੰਕ, 3 ਦੇ ਇੱਕ ਪੜਾਅ ਦੇ ਨਾਲ ਅਤੇ ਦੋ ਤਾਰੀਖਾਂ ਿਭਚਕਾਰ ਬੇਤਰਤੀਬ ਮਭਤੀ।
254 IT & ITES - COPA - (NSQF ਸੋਧੇ - 2022) - ਅਿਭਆਸ 1.42.11