Assignment_3

# Assignment_3 - Incorrect(hint 0 digits match Your guess 78...

This preview shows page 1. Sign up to view the full content.

Problem 1 Write a program that plays a guessing game with the user. The program should generate a random number between 1 and 100, then prompt the user repeatedly to guess he number. When the user guesses incorrectly, the game should give the user a hint about the number of digits of the player’s guess match the correct number. Once the user guesses correctly, the program should print a message showing the number of guesses that the user made. Sample log of the program execution may be as follows: Try to guess my two-digit number, and I’ll tell you how many digits from your guess appear in my number. Your guess? 13 Incorrect (hint: 0 digits match) Your guess? 26
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Incorrect (hint: 0 digits match) Your guess? 78 Incorrect (hint: 1 digits match) Your guess? 70 Incorrect (hint: 2 digits match) Your guess? 7 You got it right in 5 tries. Problem 2 Write a program that produces the first 11 rows of Pascal’s triangle. (Note: The numbers in the triangle have many useful mathematical properties. For example, row n of Pascal’s triangle contains the coefficients obtained when you expand the equation (x+y) n . Your program output may be the following: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online