Question: In python, 1. Assume the following code: x = int(input('Enter an integer from 1 to 100 inclusive:')) Write some more code that will examine x

In python,

1. Assume the following code:

x = int(input('Enter an integer from 1 to 100 inclusive:'))

Write some more code that will examine x and print an appropriate message:

The number you entered is too small, The number you entered is too large. ,

or The number you entered is in range.

"""

x = int(input('Enter an integer from 1 to 100 inclusive:'))

# Your code goes here

"""

2. Write a loop that uses an index to print the integers 1, 2, 3, , 100 on

separate lines. Run the program against x = [8,4,3,88,33,2,5]

"""

# Your code goes here

"""

3. Write a loop that doesnt use an index to print the items in the list on

separate lines. Run the program against x = [8,4,3,88,33,2,5]

"""

# Your code goes here

"""

4. Let n represent an integer. Write a loop that will compute

total = 1 + 2 + + n. Have the program print: The sum of the first

n integers is ___.

"""

# Your code goes here - uncomment the print statement below for the output

#print("The sum of the first %d integers is %d" % (n,total))

"""

5. Assume x is a list of integers. Write some code that will look in x for the first

occurrence of two consecutive numbers that are equal. Print The number __ occurs twice

starting at index __. if you find one. Otherwise print No consecutive occurrences.

For example, if x = [1,52,34,43,58,69,7,7,21,42], the program prints The number 7 occurs

twice starting at index 6. If x = [10,8,6,5,19], the program prints No consecutive occurrences."

The program should work for any list. Run the program against x below.

"""

x = [1,2,3,52,34,23,32,43,58,69,69,7]

"""

6. Write a function called averageTwo which is passed two integers and returns a floating-point

average of the two integers. Dont use a library function for this.

"""

# Your function goes here - uncomment the next lines for output

"""

a = 80

b = 65

x = averageTwo(a,b)

print("The average of %d and %d is %f." % (a,b,x))

a = 2

b = 3

x = averageTwo(a,b)

print("The average of %d and %d is %f." % (a,b,x))

"""

"""

7. Assume board represents a tic-tac-toe board (3 x 3). For example if,

board = [ ["X", ".", "O"],["O", "O", "."], ["X", "X", "X"]] , then player X won the

game by completing the bottom row. Each . represents an empty square. Write a function

called "allDone" which is passed a tic-tac-toe board and returns True if either player

won the game. If the game was a draw, the function returns False. A win consists of three

consecutive Xs or three consecutive Os in a row, a column, or diagonal. Any method that

works is fine, but give it some thought before you jump in.

"""

# Your function goes here - uncomment the next lines

"""

board1 = [ ["X", "O", "."],["O", "X", "."], ["X", "O", "X"]]

print("Board1 game is done? %s." % allDone(board1))

board2 = [ ["X", ".", "O"],["O", "O", "."], ["X", "X", "X"]]

print("Board2 game is done? %s." % allDone(board2))

board3 = [ ["X", "O", "X"],["O", "X", "O"], ["X", ".", "."]]

print("Board3 game is done? %s." % allDone(board3))

board4 = [ ["X", "O", "X"],["X", "X", "O"], ["O", "X", "O"]]

print("Board4 game is done? %s." % allDone(board4))

"""

"""

8. Write a function called doublePalindrome which is passed a string and returns True if the

string is a "double" palindrome (the same word forward and backwards and every letter appears

twice in a row. Examples: aabbccbbaa, a, , ccaattaacc). Otherwise return False.

"""

# Your function goes here - uncomment the next lines

"""

s = "aabbccddccbbaa"

print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))

s = "aabbcbbaa"

print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))

s = "aa"

print("Double Palindrome %s ? %s" % (s,doublePalindrome(s)))

"""

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!