Round 3 | Multimedia

Multimedia

 

Round three of multimedia we do a lot of coding and programing. The coding language that we are really focusing on is python. The program that we are use to practice and do our assignment on are Codeboad.io and Codecademy.  In our lesson we learn about:

for loop

break statement

continues

range function

nested loop

while loop

boolean

comparison

if statement

indentation

elif statement

else statement

and, or, not

condition

update

infinite while loop in while loop

break statement in while loop

continue in while loop

Below is my coding assignment.

 

from random import randint # do not delete this line

# Jr. Essential – Technology/Multimedia

# In-class exercises – January 31, 2019

# While Loops

# NOTE: your code must run without errors before you hand it in. Run and save

# your code as you complete each exercise.

 

# Exercise 0: Write a program that prints “Hello World” 5 times USING A WHILE LOOP:

# Hello World

# Hello World

# Hello World

# Hello World

# Hello World

 

n = 1

while n < 6:

   print “Hello World!”

   n += 1

 

# Exercise 1: Rewrite the following FOR LOOP using a WHILE LOOP so that the

# outputs are the same.

# Output: 0 1 4 9 16 25 36 49 64 81 100

# 1 point for correct output

# 1 point for using a while loop correctly

# for i in range(11):

#     print i ** 2

 

x = 0

while x < 11:

   print x ** 2

   x += 1

 

# Exercise 2: Using a WHILE LOOP, print all odd numbers between 0 and 100.

# 1 point for correct output

# 1 point for using a while loop correctly

# Output: 1 3 5 7 9 11 13 15 etc.

 

x = 0

while x < 101:

   if x % 2 == 1:

    print x

   x += 1

   

 

   

# Exercise 3: Using a WHILE LOOP, find the sum of all even numbers between 0 and 200.

# Output: you have to figure it out!

# 1 point for correct output

# 1 point for using a while loop correctly

 

o = 0

sum = 0

while o < 200:

   o += 2

   sum = sum + o

print sum

 

# Exercise 4: Give the user 3 tries to guess a number between 1 and 10

# (includes 1 and 10) that the computer created randomly.

# If they guess correctly within 3 tries, they win. If they don’t, they lose.

# Hint 1: use a break statement

# Hint 2: use guess = input(“Guess a number between 1 and 10 (included):”)

# 1 point for correctly using a while loop

# 1 point for losing game after 3 incorrect tries

# 1 point for winning game if guess is correct within 3 tries

# 1 point for using a break statement

# The first line of code is given to you:

 

random_number = randint(1, 10)

attempts = 0

while attempts < 3:

   guess = input(“Guess a random number between 1 and 10 :”)

   if guess == random_number:

       print “Hooray! You win”

       break

   else:

       print “Sorry! Please Try Again!”

   attempts += 1

print “Ohh No! Game Over!”

Leave a Reply

Your email address will not be published. Required fields are marked *