Question

In: Computer Science

Using Python Question 1 Write an input function. Then use it to supply the input to...

Using Python

Question 1

Write an input function. Then use it to supply the input to following additional functions:

i) Print multiplication table of the number from 1 to 12.

ii) Print the sum of all the numbers from 1 to up the number given.

iii) Print if the number supplied is odd or even.

Question 2

Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.

Solutions

Expert Solution

def mul_table(number):
    for i in range(1,13):
        print(number,'x',i,'=',number*i)  


def sum_of_num(number):
    s=0
    for i in range(1,number+1):
        s=s+i
    print("The sum of all the numbers from 1 to ",number," is : ",s)
    
def odd_even(number):
    if number%2==0:
        print("The number ",number," is : even")
    else:
         print("The number ",number," is :odd")

        
    
    
#input
number=int(input("enter number : "))

#Print multiplication table of the number from 1 to 12.
print("-----------------------multiplication table from 1 to 12 :-----------------------")
mul_table(number)


#ii) Print the sum of all the numbers from 1 to up the number given.
print("----------------------- Print the sum of all the numbers from 1 to up the number given:-----------------------")
sum_of_num(number)

#iii) Print if the number supplied is odd or even.
print("-----------------------checking whether the the number is odd or even-----------------------")
odd_even(number)

---------------------------------------------------------------------------------------------

Question 2:

import sys
#condition is always true
while(1):
    input_user=input("Enter something,to exit enter end : ")
    if(input_user=="end"):
        #exit when user type end
        sys.exit()


------------------------------------------------------------------------------------------------------------------------


Related Solutions

Pythons code using idle Write an input function. Then use it to supply the input to...
Pythons code using idle Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Parentheses Checking by python use a suitable class to write a function, given that the input...
Parentheses Checking by python use a suitable class to write a function, given that the input is the string of parentheses, check if they have the matching open and close brackets
Solve by using python function. use loop Input; Crossing Times = { 10,15,20,25} 1.Firstly person '1'...
Solve by using python function. use loop Input; Crossing Times = { 10,15,20,25} 1.Firstly person '1' and '2' cross the path with total time about 15 min(maximum of 10, 15) 2.Now the person '1' will come back with total time of '10' minutes. 3. Now, person 1 and person 3 cross the path with total of about 20 minutes .(maximum of 10,20) 4. Now the person 1 will come back in 10 mintues 5. Lastly person 1 and person 4...
Use python write a function that translates the input string into Pig Latin. The translation should...
Use python write a function that translates the input string into Pig Latin. The translation should be done word by word, where all words will be separated by only one space. You may assume that each word must have at least one vowel (a,e,i,o,u and uppercased counterparts), and there will be no punctuation or other special characters in the input string. The Pig Latin rules are as follows: For words that begin with consonants, all letters before the initial vowel...
What python codes should I use to solve this question below? Use input() function once to...
What python codes should I use to solve this question below? Use input() function once to retrieve an input and assign that input value to a variable. Check if the input contains the string “an”. If so, use input() function one more time to retrieve an input and assign the new input value to a different variable. Now, replace “an” characters in the first variable with the first two characters of the second variable if only the second variable has...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter...
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter username:") A: What is your name? B: My name is XXXX. B: What is yours? A: My name is XXXX. A: Nice to meet you. B: Nice to meet you, too. Use print statement and use input() function
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT