Assignment_3 - Incorrect (hint: 0 digits match) Your guess?...

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

View Full Document Right Arrow Icon
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
Background image of page 1
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 Pascals triangle. (Note: The numbers in the triangle have many useful mathematical properties. For example, row n of Pascals 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

This note was uploaded on 11/10/2010 for the course PROGRAMMIN 2860U taught by Professor Saman during the Fall '10 term at UOIT.

Ask a homework question - tutors are online