python - Logic Error - Need this to calculate starting at 1, not starting at 2 -


i'm trying read first 'counter' instead of calculating hours 1 0.0. should calculate speed instead, @ first hour.

if can't explain mean enough, run code. notice @ 1 (since prints long list) second number 0.0. enter in 20 mph , 15 hours. when prints 20.0 doesn't come until number 2. need pop-up @ number 1. know has basic question there is, cannot figure out :/

output:

1   0.0  2   20.0  3   40.0  4   60.0  5   80.0  6   100.0  7   120.0  8   140.0  9   160.0  10   180.0  11   200.0  12   220.0  13   240.0  14   260.0  15   280.0  distance traveled smith 300 miles. 

my code:

 def main ():      greet()      name = input("please enter name: ")     print()      speed = float(input("please enter, in miles per hour, speed (between 20-500 mph): "))      while speed < 20 or speed > 500:         print("you must enter speed between 20-500 mph")         print()         speed = float(input("please try again: "))         print()      print("that speed accepted.")     print()      time = int(input("please enter, in hours, travel time (between 2-15 hours): "))          while time < 2 or time > 15:         print("you must enter time between 2-15 hours.")         print()         time = int(input("please try again: "))         print()      print("that time accepted.")     print()      totaldistance = speed * time     totaldistance = int(totaldistance)      count in range (time):         distance = speed * count         print_data(name, distance, count, time)      print()     print("distance traveled by", name,"was", totaldistance,"miles.")   def greet ():     print()     print("this program calculates distance traveled.")     print()  def print_data (name, distance, count, time):     print()     print(format(count + 1), " ", format(distance))  main()  

your offset arises adding 1 count inside print_data, not when calculating distance.

try this:

for count in range (1, time):     distance = speed * count     print_data(distance, count) 

together with

def print_data (distance, count):     print()     print(count, distance) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -