Python 1 Write a program that counts for the user Let the us

Python:

1. Write a program that counts for the user. Let the user enter the starting number, the ending number, and the amount by which to count. Sample interaction:

Enter a starting number: 0

Enter an ending number:   50

Enter the amount by which to count:   10

0, 10, 20, 30, 40, 50

2. Create a program that gets a message from the user and then prints it out backwards.

3. Given the following definition for a function called ask_number()

def ask_number (question, low, high):

        \"\"\"Ask for a number within a range.\"\"\"

        number = random.randint(low, high)

        guesses = 1

        response = int (input(question))

        while response != number:

               if response < number:

                       print (\"too low\")

               else:

                       print (\"too high\")

               response = int (input(question))

               guesses = guesses + 1

        return guesses

Modify your Guess My Number program to use (and reuse ) the ask_number function.

# Guessing number
# Gess a number between 1 and 50

print(\"Welcome to the number guessing game!!\ \")

print(\"The object is to guess a number between 1 and 50\")

import random
number = random.randint(1,50)

guess = int(input(\"what\'s your first guess?\"))

count = 1

while guess != number:
if guess> number:
print(\"You need to guess lower than that!\")
else:
print(\"You need to guess higher than that!\")

guess = int(input(\"what\'s your next guess?\"))
count += 1

print(\"Congratulation! You got the number right! \\
It only take you\",count,\"tries!!\")

Solution

Program 1)

s = input(\"Enter starting number:\")

e = input(\"Enter ending number:\")
m = input(\"Enter the amount by which to count:\")
for i in range(s,e+1,m):
print i

\"\"\"

sample output

\"\"\"

Program 2)

msg = raw_input(\"Enter a messege\");
print msg[::-1]

\"\"\"

sample output

\"\"\"

Program 3)

import random
def ask_number (question, low, high):

\"\"\"Ask for a number within a range.\"\"\"

number = random.randint(low, high)

guesses = 1

response = int (input(question))

while response != number:
  
if response < number:
  
print (\"too low\")
  
else:
  
print (\"too high\")
  
response = int (input(question))
  
guesses = guesses + 1
  
return guesses

# Guessing number
# Gess a number between 1 and 50

print(\"Welcome to the number guessing game!!\ \")

print(\"The object is to guess a number between 1 and 50\")

count = ask_number(\"what\'s your guess?\",1,50)

print(\"Congratulation! You got the number right! \\
It only take you\",count,\"tries!!\")

\"\"\"
sample output
Welcome to the number guessing game!!

The object is to guess a number between 1 and 50
what\'s your guess? 25
too low
what\'s your guess? 37
too high
what\'s your guess? 30
too high
what\'s your guess? 27
too low
what\'s your guess? 28
too low
what\'s your guess? 29
(\'Congratulation! You got the number right! It only take you\', 6, \'tries!!\')
\"\"\"

Python: 1. Write a program that counts for the user. Let the user enter the starting number, the ending number, and the amount by which to count. Sample interac
Python: 1. Write a program that counts for the user. Let the user enter the starting number, the ending number, and the amount by which to count. Sample interac
Python: 1. Write a program that counts for the user. Let the user enter the starting number, the ending number, and the amount by which to count. Sample interac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site