0% found this document useful (0 votes)
96 views2 pages

Data Science Python Functions Assignment

The document outlines 15 programming assignments involving writing Python functions and programs to perform various tasks related to data science fundamentals. The assignments include writing functions to calculate squares, concatenate strings, check for even/odd numbers, create dictionaries from lists, calculate square roots, concatenate lists of names and numbers into tuples, print halves of tuples, add domains to usernames, use loops to print lists, convert lists to dictionaries, count words in strings, print Fibonacci sequences, play rock-paper-scissors, construct numeric patterns, and sort and print hyphen-separated words.

Uploaded by

program program
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views2 pages

Data Science Python Functions Assignment

The document outlines 15 programming assignments involving writing Python functions and programs to perform various tasks related to data science fundamentals. The assignments include writing functions to calculate squares, concatenate strings, check for even/odd numbers, create dictionaries from lists, calculate square roots, concatenate lists of names and numbers into tuples, print halves of tuples, add domains to usernames, use loops to print lists, convert lists to dictionaries, count words in strings, print Fibonacci sequences, play rock-paper-scissors, construct numeric patterns, and sort and print hyphen-separated words.

Uploaded by

program program
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The British College

Fundamentals of Data Science Level 3

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.

name_list = [“Dan Mace”, “Connor Meyer”, “Adam Smith”, “John Watson”]


number_list = [98980000, 777890879, 123087699, 960008779]

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 “@[Link]” 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@[Link], rsouza@[Link],
lgarber@[Link], aghods@[Link], shassan@[Link],
proy@[Link]]

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'

Your output must be as follows:

number of words: 12

12. Write a function to print Fibonacci sequence up-to the given term.

For example: If a user inputs 7, your function should print: 1, 1, 2, 3, 5, 8, 13


if a user inputs 9, your function should print: 1, 1, 2, 3, 5, 8, 13, 21, 34

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.

14. Write a Python program to construct the following pattern.


1
22
333
4444
55555
666666
7777777
88888888
999999999

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:

If your input is : s-i-t-c-o-m

Your output should be : c-i-m-o-s-t

You might also like