Rate Movies in Python -
i'm trying write program display user’s movie rating. application should allow user enter ratings 5 different movies. each rating should number 1 through 10 only. application should graph ratings using horizontal bar chart made of row of asterisks ().each row should contain 1 10 asterisks (). number of asterisks depends on movie’s rating. have use tuple store name of 5 movies. i'm new @ programming please nice lol.
this have far i'm struggling:
movies = ("shrek", "platoon", "scary movie ii", "gone wind", "harvey", "7:4") rating = int(input ("enter movie rating: ")) in range(1,11): print ("rating movie: ", movies[rating]) while rating < 0 or rating > 10: ratings = int(input("enter movie rating: ", rating)) j in range(rating): print ("*"*5,)
first, tuples aren't this. can use list instead. it's similar worth switching using [ square brackets ]
movies = ["shrek", "platoon", "scary movie ii", "gone wind", "harvey", "7:4"]
next, want loop go on every movie, not range of values user allowed put in. can loop on list with
for movie in movies: print ("rating movie: ", movie)
so each part of list temporarily stored 'movie' 1 one rest of code runs.
next, need first set rating 0, while loop run @ least once before user has given rating.
don't use input can behave in unintended ways. "raw_input" want use because takes in input string.
also, int() you'll error if types can't turned whole number. should use called try, except. these allow code anticipate error , continue running if comes up.
rating = 0 while rating < 1 or rating > 10: try: ratings = int(raw_input("enter movie rating: ")) except valueerror: print ("that's not valid number.")
and lastly, don't need loop final print, multiply string rating.
print ("*"*rating)
Comments
Post a Comment