Study group Slovenia

Thanks. :sunglasses:

@vika in the for loop you have a statement:

for student in students:
    return get_average(student)
    result.append(get_average(student))

but because you are using return before you append the average to the result variable, you are always just getting the average from the first item in the students list.
You start the function, but then you tell it to stop and return something in the first turn of the loop.
Delete the:

 return get_average(student)

and try again.

Good job!

@Mooc_e, thanks, but it didn’t work. I found a solution for 8/9 (Student Becomes the Teacher) :sunglasses:

students = [lloyd, alice, tyler]

def get_class_average(students):
    results = []    
    for student in students:
        results.append(get_average(student))
    return float(sum(results)/len(results))
1 Like

Is anyone in Study group Slovenia working on Exercise 1.7 – Rock, Paper, Scissors from MIT 6.189 Homework 1? Among the MMOOC in general, we have come up with a variety of approaches, and it would be interesting to see additional examples of code.

Here’s mine:

player_1 = raw_input(“Player 1, choose your weapon.”)
player_2 = raw_input(“Player 2, choose your weapon.”)
if (player_1 == ‘rock’ and player_2 == ‘rock’):
print "It’s a tie!"
elif (player_1 == ‘rock’ and player_2 == ‘paper’):
print "Player 2 wins!"
elif (player_1 == ‘rock’ and player_2 == ‘scissors’):
print "Player 1 wins!"
elif (player_1 == ‘paper’ and player_2 == ‘rock’):
print "Player 1 wins!"
elif (player_1 == ‘paper’ and player_2 == ‘paper’):
print "It’s a tie!"
elif (player_1 == ‘paper’ and player_2 == ‘scissors’):
print "Player 2 wins!"
elif (player_1 == ‘scissors’ and player_2 == ‘rock’):
print "Player 2 wins!"
elif (player_1 == ‘scissors’ and player_2 == ‘paper’):
print "Player 1 wins!"
elif (player_1 == ‘scissors’ and player_2 == ‘scissors’):
print "It’s a tie!"
else:
print “This is not a valid input.”

1 Like

vijolica9:

Thanks for posting your code.

I hope your study group in Slovenia is enjoying the course.

Something that @TutorialDoctor posted that helped me shorten my solution to this one was to check for a tie first, like this …

if p1==p2:
    print "Tie"

By doing something similar, I was able eliminate several lines. In the case of your code, if you do this near the beginning …

if (player_1 == player_2):
    print "It's a tie!"

You could eliminate lines such as …

elif (player_1 == 'paper' and player_2 == 'paper'):
    print "It's a tie!"

The same goes for 'rock' and 'scissors'.

@dirk described how we can format our posted code in this post, so that indentation gets displayed.