Python Forum
How to solve this task? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: How to solve this task? (/thread-35727.html)



How to solve this task? - DERO - Dec-06-2021

Imagine yourself as a space ranger. Create a function that has the distances from Earth to the five nearest
stars (find the distances and names of the stars on the Internet).The user enters the speed of his ship and receives time (in hours) in which it will reach each star.If it will take more than 10 years to travel, display on the screen the recommendation to work on the ship and the speed which is needed for the voyage to last less than 10 years.
import time
alphaCentauri = 4
alphaCentauriB = 4.5
barnard = 5
lumanSixteen = 6
wolfThree = 13
speed= int(input("скорость корабля:"))
time = alphaCentauri / speed  #other stars
print("время в часах:", time,"час(ов)" )
This is all that i could write


RE: How to solve this task? - Gribouillis - Dec-06-2021

Hint: use a list instead of five variables
stars = [('Alpha Centauri', 4), ('Alpha Centauri B', 4.5), ...]



RE: How to solve this task? - BashBedlam - Dec-06-2021

Here is how you can determine the hours and years that the journey will take at a given speed entered as kilometers per hour.
LIGHT_SPEED = 1079252849 # kilometers per hour
HOURS_PER_YEAR = 8766

alphaCentauri = 4

kilometers_per_hour = int (input ("Введите скорость в километрах в час:"))
speed = kilometers_per_hour / LIGHT_SPEED
years = alphaCentauri / speed
hours = years * HOURS_PER_YEAR

print("время в часах:", hours ,"час(ов)")
print ("Время в годах:", years, "год(ы)")