samedi 12 février 2022

Need help comparing a random competitor to user input

So basically i am having trouble with this part of this project I'm working on. I need to create a competitor that has a random amount of viewers (between 1 and 100). Compute the amount of viewers for competitor (random, this should vary each time). Each of their viewer watches 1 video on their channel that is between 1 and 5 minutes long (choose this randomly per viewer). Compute the total amount of minutes your competitor’s viewers spent watching their channel. And then figure out which channel had more watch time. Output whether it was your channel, their channel, or a tie! To make sure that you’re correct, output the total time watched for each channel. Can someone help me find the correct way to go about this problem I'm really struggling. I'm assuming I need to repeat some of the process I did for the first channel. This is my code so far:

import random

n = int(input("How many youtube videos do you have on your channel? "))
my_dict = {}


for i in range(n):
    titles=input("What is the title?")
    length=float(input("What is the video's length?"))
    my_dict[titles] = length
print ("You have", n,"videos on your youtube. The names of your youtube videos are:", my_dict)


shortest = min(my_dict.values())
longest = max(my_dict.values())

print("Your shortest video is", shortest,"minutes long.")
print("Your longest video is", longest,"minutes long.")

average = sum(my_dict.values())/ len(my_dict)


print("Your average length is", format(average, ".3f"))


print("Part 3 - Let's talk about subscribers.")

sub = int(input("How many subscribers do you currently have? "))
total_time = 0 
total_time_eachvid = {}


if sub >= 0:
    print('Watch time statistics:')
    for i in range(sub):
        choice = random.choice(list(my_dict))
        if choice in total_time_eachvid:
            total_time_eachvid[choice] += my_dict[choice] 
        else:
            total_time_eachvid[choice] = my_dict[choice] 
        print("Subsriber watched for", my_dict[choice], "minutes.") 
        total_time += my_dict[choice]
    print('\n')
print("Total Time spent by all viewers is:", total_time)
print("Total time spent on each video", total_time_eachvid)

print("Part 4 - Let's compare our channel to our competitor!")

projects due soon so please help!!

print("Let's compare our channel to our competitor!")

comp = random.randint(1,100)
print("Your competitor has", comp,"subscribers")



Aucun commentaire:

Enregistrer un commentaire