Professional Documents
Culture Documents
Assignment 2:) Where A Is The Input Value To The Function
Assignment 2:) Where A Is The Input Value To The Function
Assignment 2:) Where A Is The Input Value To The Function
Assignment 2
1. Write a python function that computes the square of a number. The function should return the
output as a tuple in the following form: (a, a2) where a is the input value to the function.
2. Write a function that can accept two strings as input and concatenate them and then print it as an
output.
3. Write a function that can accept an integer number as an input and print "Even number" if the
number is even, otherwise print "Odd number".
4. Write a function that can print a dictionary where the keys are numbers between 1 and 20 (both
included) and the values are square of keys.
5. Write a function to compute the square-root of a given number. If the given number is negative,
your function should give an error message.
6. Write a function to input two separate lists, one with names (name_list) and another with
numbers (number_list). Your function should then output another list (output_list) which contains
tuples of names and number.
output_list = [ (Dan Mace, 98980000), (Connor Meyer, 777890879), (Adam Smith, 123087699), (John
Watson, 960008779) ]
7. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line
and the last half values in another line.
8. Write a function that takes in a list of usernames of students. The function should then output
another list which returns the email addresses by adding “@thebritishcollege.edu.np” to the
usernames in the list. The output of your function should be a list.
Input:
student_username = [ksmith, rsouza, lgarber, aghods, shassan, proy]
Output:
student_email = [ksmith@thebritishcollege.edu.np, rsouza@thebritishcollege.edu.np,
lgarber@thebritishcollege.edu.np, aghods@thebritishcollege.edu.np, shassan@thebritishcollege.edu.np,
proy@thebritishcollege.edu.np]
9. In the list given below, use a while loop to print the output. Your loop should run until all the
items in the list have been printed.
name_list = [ (Dan Mace, 98980000), (Connor Meyer, 777890879), (Adam Smith, 123087699), (John
Watson, 960008779) ]
Your output should look like:
Name: Dan Mace
Contact no: 98980000
.
.
.
10. Write a function that accepts a list of tuples as an input, and outputs the values as a dictionary
shown below:
input_list = [ (Dan Mace, 98980000), (Connor Meyer, 777890879), (Adam Smith, 123087699), (John
Watson, 960008779) ]
output_dict = {Dan Mace: 98980000, Connor Meyer: 777890879, Adam Smith: 123087699, John Watson:
960008779}
11. Write a function to go through a string and count the number of words in the given string.
input_str = 'If you count the words in this sentence you will get twelve'
number of words: 12
12. Write a function to print Fibonacci sequence up-to the given term.
13. Write a program to play a game of rock, paper and scissor between two players. Take two user
inputs from the keyboard and according to user's choice decide who wins.
15. Write a Python function that accepts a hyphen-separated sequence of words as input and prints
the words in a hyphen-separated sequence after sorting them alphabetically.
For example: