Input and Output Code#

  • Please solve the following questions using Python code.  

Question-1#

Display the first 3 characters of your first name by using the character *.

Solution

print('*     *   *     *   * * * *   ')
print(' *   *    *     *   *         ')
print('   *      *     *   * * * *   ')
print('   *      *     *         *   ')
print('   *      * * * *   * * * *   ')

Question-2#

  • Use the given variables to print the following statement:
    My name is Michael. I am from Germany. I am 25 years old.

  • Be careful about spaces and punctuations.

    • name = ‘Michael’

    • age = 25

    • country = ‘Germany’

Solution

name = 'Michael'
age = 25
country = 'Germany'

print('My name is ', name, '. I am from ', country, '. I am ', age, ' years old.', sep='')

Question-3#

Write a program that prompts the user for 4 numbers using 4 input functions.

  • Find the sum of these numbers and assign it to a variable.

  • Find the product of these numbers and assign it to a variable.

  • Print the sum and product of these numbers on two separate lines using a single print function.

Solution

num1 = float(input('Number1: '))
num2 = float(input('Number2: '))
num3 = float(input('Number3: '))
num4 = float(input('Number4: '))

total = num1 + num2 + num3 + num4
product = num1 * num2 * num3 * num4

print('Sum: ', total, '\nProduct:', product)

Question-4#

  • Use the given variables to print Bill- -Gates by using five different codes.

    • first_name = ‘Bill’

    • last_name = ‘Gates’

Solution

first_name = 'Bill'
last_name = 'Gates'
print(first_name, last_name, sep='- -')
print(first_name +'- -'+ last_name)
print(first_name +'-'+' -'+ last_name)
print(first_name +'- '+'-'+ last_name)
print(first_name +'-'+' '+'-'+ last_name)

Question-5#

Write a program which prompts the user for an integer.

  • Find the square of the given number.

  • Print the following statement:

    • square(number) = square of the number

    • Example: If the given number is 3 then the output should be square(3)=9

    • Example: If the given number is 5 then the output should be square(5)=25

Solution

number = int(input('Enter an integer: '))

square = number**2

print('square(', number, ')=', square, sep='')