Programming Homework Help

Programming Homework Help. UH Downtown Phyton Spyder Code Simulate a Slot Machine Question

Can you help me understand this Python question?

Question 1

You python code will simulate a slot machine: it will generate a ticket of 3 random numbers. You need generate 1000 tickets. These 3 numbers must range from 1-9. When these three numbers are all 7s, or 9s, you win this game. Every time you won, print out ‘Bingo! You won!’

You must print out each ticket, then count how many times you had won, and print how many times you won at the end of the program.

Example output:

3 6 9

8 9 4

7 7 7

Bingo! You won!

8 9 5

9 9 9

Bingo! You won!

3 9 7

2 9 6

You won 2 times!

Question 2.

This question will focus on String manipulation.

We will have a default string like: A_Beautiful_Rose_Is_Blooming_In_The_Garden.

Each word is separated by a underscore char “_”.

You need to do following steps:

2.1 (5 pts) Split the sentence by unserscore “_”, and store them in a word list, print out that list

2.2 (5 pts) Change all letters of 1st word to upper case, the rest of the words all to lower case, then print the word list out

2.3 (5 pts) Join the word list back to a string using character “*”, print it out

2.4 (5 pts) Replace the word “rose” with your own favorite flower, daisy, gardenia, lily, tulip.

2.5 (5 pts) Reverse the new sentence and print them out

Sample output:

Please type a sentence: A_Beautiful_Rose_Is_Blooming_In_The_Garden.

2.1 output: [‘A’, ‘Beautiful’, ‘Rose’, ‘Is’, ‘Blooming’, ‘In’, ‘The’, ‘Garden.’]

2.2 output: [‘A’, ‘beautiful’, ‘rose’, ‘is’, ‘blooming’, ‘in’, ‘the’, ‘garden.’]

2.3 output: A*beautiful*rose*is*blooming*in*the*garden.

2.4 output: A*beautiful*tulip*is*blooming*in*the*garden.

2.5 output: .nedrag*eht*ni*gnimoolb*si*pilut*lufituaeb*A

Question 3.

Return the sum of the numbers in the array that are between 6 and 7. The first 6 should be excluded, and all 7’s should be excluded). Any number inside a 6 and 7 must be added to you sum, numbers outside of 6 and 7 should not be added.

Return 0 for no numbers.

Example output:

Sum67([])→ 0

sum67([1, 2, 2]) → 0

sum67([1, 6, 6, 10]) → 16

sum67([1, 6, 6, 10, 7]) → 16

sum67([1, 6, 6, 10, 7, 8, 7, 6, 1, 7, 7]) → 17

sum67([1, 1, 6, 7, 2]) → 0

Question 4.

This question focuses on Dictionary. We want to create a Dictionary to simulate the Hotel Booking list.

BookingNumber (int), Guest(String, firstname, lastname), RoomType(String, “suit”,“standard”), Price(Float), Date(String, “7/2-7/5”)

  1. Create an empty BookingDict Dictionary, it must be a global variable. (in main function)
  2. Define a function call createBooking(BookingNumber, Guest, RoomType, Price, Date). This function will add a new item to your BookingDict, with a Booking number that is an integer, and keeps increasing with each new book added.
  3. Define a function call sortBooking(). In this function, you will sort your Dictionary first based on the guest then by the Price.
  4. Call your createBooking function 5 Times to generate a BookingDict of 5 bookings. Display these five bookings.
  5. Call your sortBy functions to sort the BookingDict, then print out the sorted bookings.

Question 5.

Max Subarray Sum: Given an array of integers, find the subarray which contains max sum.

For example,

Input: Given integer array :”1, 2, 4, -6, 3, 4, -1, 9″,

Output: “16”

Input: Given integer array :”1, 2, 4, -9, 3, 4, -1, 9″,

Output: “15”

Input: Given integer array :”1, 2, 4, -6, 3, 4, -6, 5″,

Output: “7”

Input: Given integer array :”1, 2, 4, -6, 3, 4, -8, 9″,

Output: “9”

Divide and Conquer:

There are three key words:

  1. Find all subarrays
  2. Find the sum of this subarray
  3. Find the max sum and print it out

Programming Homework Help