Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The below is using Python programming ============================== (A) Write a Python program that prints a square of size depending on an entered value. The program

The below is using Python programmingimage text in transcribed

==============================

(A)

Write a Python program that prints a square of size depending on an entered value. The program first reads in the size of the square, and then prints the square with a pattern according to the examples below. Your program should print error message and then terminate the execution if the entered size is less than 1 or exceed 20. The figure shows two different executions of the program. Output should be below:

Enter the size of pattern: 5

=====

=234=

=345=

=456=

=====

Enter the size of pattern: 8

========

=234567=

=345678=

=456789=

=567890=

=678901=

=789012=

==========================

(B) Write a Python program for this question

Because of the great reduction in the number of oversea traveller recently a resort hotel wishes to attract more local customers and to start a new promotion campaign. At check-in, a customer would play a game called Go-Up, which involves rolling a 6-face die at most 5 times, and the customer would win a cash prize if the second time is not smaller than the first time, and the third time is not smaller than the second time, and similarly for the fourth time and the fifth time.

For example, the customer wins if the rolls are 3, 5, 5, 6, and 6, and the customer loses if the rolls are 3 and 2 (i.e. no need to consider the third roll).

In order to determine the amount of cash prize, the management wishes to know the probability (i.e. percentage of all cases) that a person could win. A simulation of playing the game many times is needed to estimate the probability. Each time, the program simulates the rolling of a die in Go-Up and find out whether the outcome is winning or losing.

The given code as below:

import random

freq = [0] * 7

for e in range(0, 100):

number = random.randint(1, 6)

freq[number] += 1

print('Num Freq')

for i in range(1, 7):

print(' {} {} '.format(i, freq[i]))

==================================

(C) Write a Python program for this question

image text in transcribed

Specific Requirements of Question Specifics Data Validation The range of the input from the user and parameter values should be checked to avoid causing your program to crash. This is about checking the range and see if the value making sense and not causing an execution error. For example, the height of square should be check against negative value (which does not make sense) (which would cause the program to crash). However, you need not deal with the cases that have been assumed in the question itself. (c) Write a program that reads in the age of the user, and then prints whether the user is eligible for "fruit subsidy" for elderly. The rules are given below. Age Output Message

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the best conclusion for Xbar Chart? UCL A X B C B A LCL

Answered: 1 week ago