so my teacher gave us this assignment, she showed us a video in the class and then we had to replicate it by ourselves. i, unfortunately, do not have that link, but if i were to explain it, we had to print a 'snake' (almost like a parabola, according to my observations and the way in which i had coded it in) from astericks, where the user specifies the number of lines and curvature (in the demo, she used values between (-1,1) for the curvature so i had checked it with those only).
my initial part of the code gives the desired result-
(also can someone explain here why taking i = y and then for each loop assuming i-=0.25 will not give the same output?)
i have attached the image of the output for this.
anyways, this opens like y^2 = 4ax, but i also wanted it to function like y^2 = -4ax, so i added this -
can someone correct my logic or give any hints? i am fairly new to python and to this forum, so i would appreciate if a simpler explanation could be given. thank you and apologies if there is any mistake from my side!
my initial part of the code gives the desired result-
print('Enter the number of lines and curvature') lines = int(input()) curvature = float(input()) y = lines // 2 i = -y if curvature > 0: while i <= y: x = (i ** 2 / 2) * curvature if x >= 0.01: spaces = int(x / 0.01) - 2 print(" " * spaces + "*") else: print("*") i += 0.25i had assumed the units across x axis as 0.01 and for y axis as 0.25 (no specific reason, i just did so to match it up with the mental image i had from the video we were shown.)
(also can someone explain here why taking i = y and then for each loop assuming i-=0.25 will not give the same output?)
i have attached the image of the output for this.
anyways, this opens like y^2 = 4ax, but i also wanted it to function like y^2 = -4ax, so i added this -
elif curvature < 0: while i <= y: x = (i ** 2 / 2) * curvature if x >= 0.01: spaces = (int(((y**2/2)* curvature)/0.01)-2) - (int(x / 0.01) - 2) if spaces >= 0: print(" " * spaces + "*") else: print(" " * (-spaces) + "*") # trying to use the modulus value else: print("*") i += 0.25my reasoning was that the first line should remain now without any space, therefore i subtracted the values in the new spaces. but this pieces gives a straight line of astericks.
can someone correct my logic or give any hints? i am fairly new to python and to this forum, so i would appreciate if a simpler explanation could be given. thank you and apologies if there is any mistake from my side!