0% found this document useful (0 votes)
21 views1 page

PP Assignment 6

The document outlines 10 programming assignments involving defining various functions in Python. Some functions include: 1) defining a function to calculate the sum of two integers, 2) defining functions to encrypt and decrypt text using Caesar and permutation ciphers, 3) defining a function to concatenate two strings, 4) defining a function to print squares of numbers from 1 to 20 as dictionary keys and values, 5) defining a function to print the first 5 elements of a list containing squares of numbers from 1 to 20.

Uploaded by

shw17318
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)
21 views1 page

PP Assignment 6

The document outlines 10 programming assignments involving defining various functions in Python. Some functions include: 1) defining a function to calculate the sum of two integers, 2) defining functions to encrypt and decrypt text using Caesar and permutation ciphers, 3) defining a function to concatenate two strings, 4) defining a function to print squares of numbers from 1 to 20 as dictionary keys and values, 5) defining a function to print the first 5 elements of a list containing squares of numbers from 1 to 20.

Uploaded by

shw17318
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
You are on page 1/ 1

Assignment # 6 (Date: 09/09/2020)

1. Define a function that can receive two integer numbers form user and
compute their sum and then print it on console.
2. Write a function which takes a text and encrypts it with a Caesar cipher.
This is one of the simplest and most commonly known encryption techniques.
Each letter in the text is replaced by a letter some fixed number of
positions further in the alphabet. What about decrypting the coded text?
The Caesar cipher is a substitution cipher.

3. We can create another substitution cipher by permutating the alphabet


and map the letters to the corresponding permutated alphabet. Write a
function which takes a text and a dictionary to decrypt or encrypt the
given text with a permutated alphabet.

[ Hint: import strings


from random import sample
alphabet = string.ascii_letters
permutated_alphabet = sample(alphabet, len(alphabet))]

4. Define a function that can accept two strings as input and concatenate
them and then print it in console.
5. Define a function which can print a dictionary where the keys are
numbers between 1 and 20 (both included) and the values are square of
keys.
6. Define a function which can generate a list where the values are square
of numbers between 1 and 20 (both included). Then the function needs to
print the first 5 elements in the list.
7. The Fibonacci Sequence is computed based on the following formula:
f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1

Write a function to compute the value of f(n) with a given n input by


console.

8. Write a Python program to detect the number of local variables declared


in a function.
9. Write a Python funcion that changes the value of a variable defined
inside a function from outside of the function.
10. Write a Python function in which one argument takes the default value.

You might also like