Python-Chap5 AND 6 - Python Loops(Activity 5.10.1 By Cerca...

This preview shows page 1 - 4 out of 4 pages.

Python Loops (Activity 5.10.1)By Cerca Trova On 1:15 PMQuestion: "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y)and the user must repeat the sequence. Create a for loop that compares the two strings. For eachmatch, add one point to user_score. Upon a mismatch, end the game. Ex: The following patternsyield a user_score of 4:simonPattern: R, R, G, B, R, Y, Y, B, G, YuserPattern: R, R, G, B, B, R, Y, B, G, YCode:user_score = 0simon_pattern = 'RRGBRYYBGY'user_pattern = 'RRGBBRYBGY'for i in range(len(simon_pattern)):x = simon_pattern[i]y = user_pattern[i]if x == y:user_score = user_score + 1
else:breakprint ('User score:', user_score)Python Return (Activity 6.3.2)By Cerca Trova On 7:38 PMQuestion:Define a function pyramid_volume with parameters base_length, base_width, andpyramid_height, that returns the volume of a pyramid with a rectangular base.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture