Skip to content

This repository contains the Basic coding Assignments of Python.

Notifications You must be signed in to change notification settings

Anujy17/Coding_Basic_Assignment_Ineuron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Basic Programming Assignment

Programming_Assingment1

  1. Write a Python program to print "Hello Python"?
  2. Write a Python program to do arithmetical operations addition and division.?
  3. Write a Python program to find the area of a triangle?
  4. Write a Python program to swap two variables?
  5. Write a Python program to generate a random number?

Programming_Assingment2

  1. Write a Python program to convert kilometers to miles?
  2. Write a Python program to convert Celsius to Fahrenheit?
  3. Write a Python program to display calendar?
  4. Write a Python program to solve quadratic equation?
  5. Write a Python program to swap two variables without temp variable?

Programming_Assingment3

  1. Write a Python Program to Check if a Number is Positive, Negative or Zero?
  2. Write a Python Program to Check if a Number is Odd or Even?
  3. Write a Python Program to Check Leap Year?
  4. Write a Python Program to Check Prime Number?
  5. Write a Python Program to Print all Prime Numbers in an Interval of 1-10000?

Programming_Assingment4

  1. Write a Python Program to Find the Factorial of a Number?
  2. Write a Python Program to Display the multiplication Table?
  3. Write a Python Program to Print the Fibonacci sequence?
  4. Write a Python Program to Check Armstrong Number?
  5. Write a Python Program to Find Armstrong Number in an Interval?
  6. Write a Python Program to Find the Sum of Natural Numbers?

Programming_Assingment5

  1. Write a Python Program to Find LCM?
  2. Write a Python Program to Find HCF?
  3. Write a Python Program to Convert Decimal to Binary, Octal and Hexadecimal?
  4. Write a Python Program To Find ASCII value of a character?
  5. Write a Python Program to Make a Simple Calculator with 4 basic mathematical operations?

Programming_Assingment6

  1. Write a Python Program to Display Fibonacci Sequence Using Recursion?
  2. Write a Python Program to Find Factorial of Number Using Recursion?
  3. Write a Python Program to calculate your Body Mass Index?
  4. Write a Python Program to calculate the natural logarithm of any number?
  5. Write a Python Program for cube sum of first n natural numbers?

Programming_Assingment7

  1. Write a Python Program to find sum of array?
  2. Write a Python Program to find largest element in an array?
  3. Write a Python Program for array rotation?
  4. Write a Python Program to Split the array and add the first part to the end?
  5. Write a Python Program to check if given array is Monotonic?

Programming_Assingment8

  1. Write a Python Program to Add Two Matrices?
  2. Write a Python Program to Multiply Two Matrices?
  3. Write a Python Program to Transpose a Matrix?
  4. Write a Python Program to Sort Words in Alphabetic Order?
  5. Write a Python Program to Remove Punctuation From a String?

Programming_Assingment9

  1. Write a Python program to check if the given number is a Disarium Number?
  2. Write a Python program to print all disarium numbers between 1 to 100?
  3. Write a Python program to check if the given number is Happy Number?
  4. Write a Python program to print all happy numbers between 1 and 100?
  5. Write a Python program to determine whether the given number is a Harshad Number?
  6. Write a Python program to print all pronic numbers between 1 and 100?

Programming_Assingment10

  1. Write a Python program to find sum of elements in list?
  2. Write a Python program to Multiply all numbers in the list?
  3. Write a Python program to find smallest number in a list?
  4. Write a Python program to find largest number in a list?
  5. Write a Python program to find second largest number in a list?
  6. Write a Python program to find N largest elements from a list?
  7. Write a Python program to print even numbers in a list?
  8. Write a Python program to print odd numbers in a List?
  9. Write a Python program to Remove empty List from List?
  10. Write a Python program to Cloning or Copying a list?
  11. Write a Python program to Count occurrences of an element in a list?

Programming_Assingment11

  1. Write a Python program to find words which are greater than given length k?
  2. Write a Python program for removing i-th character from a string?
  3. Write a Python program to split and join a string?
  4. Write a Python to check if a given string is binary string or not?
  5. Write a Python program to find uncommon words from two Strings?
  6. Write a Python to find all duplicate characters in string?
  7. Write a Python Program to check if a string contains any special character?

Programming_Assingment12

  1. Write a Python program to Extract Unique values dictionary values?
  2. Write a Python program to find the sum of all items in a dictionary?
  3. Write a Python program to Merging two Dictionaries?
  4. Write a Python program to convert key-values list to flat dictionary?
  5. Write a Python program to insertion at the beginning in OrderedDict?
  6. Write a Python program to check order of character in string using OrderedDict()?
  7. Write a Python program to sort Python Dictionaries by Key or Value?

Programming_Assingment13

  1. a program that calculates and prints the value according to the given formula:

Q = Square root of [(2 * C * D)/H]

Following are the fixed values of C and H:

C is 50. H is 30.

D is the variable whose values should be input to your program in a comma-separated sequence.

Example

Let us assume the Write following comma separated input sequence is given to the program:

100,150,180

The output of the program should be:

18,22,24

  1. Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.

Note: i=0,1.., X-1; j=0,1,¡¬Y-1.

Example

Suppose the following inputs are given to the program:

3,5

Then, the output of the program should be:

[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

  1. Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.

Suppose the following input is supplied to the program:

without,hello,bag,world

Then, the output should be:

bag,hello,without,world

  1. Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.

Suppose the following input is supplied to the program:

hello world and practice makes perfect and hello world again

Then, the output should be:

again and hello makes perfect practice world

  1. Write a program that accepts a sentence and calculate the number of letters and digits.

Suppose the following input is supplied to the program:

hello world! 123

Then, the output should be:

LETTERS 10

DIGITS 3

  1. A website requires the users to input username and password to register. Write a program to check the validity of password input by users.

Following are the criteria for checking the password:

  1. At least 1 letter between [a-z]

  2. At least 1 number between [0-9]

  3. At least 1 letter between [A-Z]

  4. At least 1 character from [$#@]

  5. Minimum length of transaction password: 6

  6. Maximum length of transaction password: 12

Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma.

Example

If the following passwords are given as input to the program:

ABd1234@1,a F1#,2w3E*,2We3345

Then, the output of the program should be:

ABd1234@1

Programming_Assingment14

  1. Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.

  2. Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.

Suppose the following input is supplied to the program:

New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.

Then, the output should be:

2:2

3.:1

3?:1

New:1

Python:5

Read:1

and:1

between:1

choosing:1

or:2

to:1

  1. Define a class Person and its two child classes: Male and Female. All classes have a method "getGender" which can print "Male" for Male class and "Female" for Female class.

  2. Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"].

  3. Please write a program to compress and decompress the string "hello world!hello world!hello world!hello world!".

  4. Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list.

Programming_Assingment15

  1. Please write a program using generator to print the numbers which can be divisible by 5 and 7 between 0 and n in comma separated form while n is input by console. Example: If the following n is given as input to the program: 100 Then, the output of the program should be: 0,35,70

  2. Please write a program using generator to print the even numbers between 0 and n in comma separated form while n is input by console. Example: If the following n is given as input to the program: 10 Then, the output of the program should be: 0,2,4,6,8,10

  3. 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 Please write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console. Example: If the following n is given as input to the program: 7

Then, the output of the program should be: 0,1,1,2,3,5,8,13

  1. Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the user name of a given email address. Both user names and company names are composed of letters only. Example: If the following email address is given as input to the program: john@google.com Then, the output of the program should be: john

  2. Define a class named Shape and its subclass Square. The Square class has an init function which takes a length as argument. Both classes have a area function which can print the area of the shape where Shape's area is 0 by default.

Programming_Assingment16

  1. Write a function that stutters a word as if someone is struggling to read it. The first two letters are repeated twice with an ellipsis ... and space after each, and then the word is pronounced with a question mark ?. Examples stutter("incredible") âžž "in... in... incredible?"

stutter("enthusiastic") âžž "en... en... enthusiastic?"

stutter("outstanding") âžž "ou... ou... outstanding?"

Hint :- Assume all input is in lower case and at least two characters long.

2.Create a function that takes an angle in radians and returns the corresponding angle in degrees rounded to one decimal place. Examples radians_to_degrees(1) âžž 57.3

radians_to_degrees(20) âžž 1145.9

radians_to_degrees(50) âžž 2864.8

  1. In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number. Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise. Examples is_curzon(5) âžž True

2 ** 5 + 1 = 33

2 * 5 + 1 = 11

33 is a multiple of 11

is_curzon(10) âžž False

2 ** 10 + 1 = 1025

2 * 10 + 1 = 21

1025 is not a multiple of 21

is_curzon(14) âžž True

2 ** 14 + 1 = 16385

2 * 14 + 1 = 29

16385 is a multiple of 29

  1. Given the side length x find the area of a hexagon.

Examples area_of_hexagon(1) âžž 2.6

area_of_hexagon(2) âžž 10.4

area_of_hexagon(3) âžž 23.4

  1. Create a function that returns a base-2 (binary) representation of a base-10 (decimal) string number. To convert is simple: ((2) means base-2 and (10) means base-10) 010101001(2) = 1 + 8 + 32 + 128. Going from right to left, the value of the most right bit is 1, now from that every bit to the left will be x2 the value, value of an 8 bit binary numbers are (256, 128, 64, 32, 16, 8, 4, 2, 1). Examples binary(1) âžž "1"

1*1 = 1

binary(5) âžž "101"

11 + 14 = 5

binary(10) âžž "1010"

12 + 18 = 10

Programming_Assingment17

  1. Create a function that takes three arguments a, b, c and returns the sum of the numbers that are evenly divided by c from the range a, b inclusive. Examples evenly_divisible(1, 10, 20) âžž 0

No number between 1 and 10 can be evenly divided by 20.

evenly_divisible(1, 10, 2) âžž 30

2 + 4 + 6 + 8 + 10 = 30

evenly_divisible(1, 10, 3) âžž 18

3 + 6 + 9 = 18

  1. Create a function that returns True if a given inequality expression is correct and False otherwise. Examples correct_signs("3 < 7 < 11") âžž True

correct_signs("13 > 44 > 33 > 1") âžž False

correct_signs("1 < 2 < 6 < 9 > 3") âžž True

  1. Create a function that replaces all the vowels in a string with a specified character. Examples replace_vowels("the aardvark", "#") âžž "th# ##rdv#rk"

replace_vowels("minnie mouse", "?") âžž "m?nn?? m??s?"

replace_vowels("shakespeare", "") âžž "shksp**r"

  1. Write a function that calculates the factorial of a number recursively. Examples factorial(5) âžž 120

factorial(3) âžž 6

factorial(1) âžž 1

factorial(0) âžž 1

  1. Hamming distance is the number of characters that differ between two strings. To illustrate: String1: "abcbba" String2: "abcbda"

Hamming Distance: 1 - "b" vs. "d" is the only difference. Create a function that computes the hamming distance between two strings. Examples hamming_distance("abcde", "bcdef") âžž 5

hamming_distance("abcde", "abcde") âžž 0

hamming_distance("strong", "strung") âžž 1

Programming_Assingment18

  1. Create a function that takes a list of non-negative integers and strings and return a new list without the strings. Examples filter_list([1, 2, "a", "b"]) âžž [1, 2]

filter_list([1, "a", "b", 0, 15]) âžž [1, 0, 15]

filter_list([1, 2, "aasf", "1", "123", 123]) âžž [1, 2, 123]

  1. The "Reverser" takes a string as input and returns that string in reverse order, with the opposite case. Examples reverse("Hello World") âžž "DLROw OLLEh"

reverse("ReVeRsE") âžž "eSrEvEr"

reverse("Radar") âžž "RADAr"

  1. You can assign variables from lists like this: lst = [1, 2, 3, 4, 5, 6] first = lst[0] middle = lst[1:-1] last = lst[-1]

print(first) âžž outputs 1 print(middle) âžž outputs [2, 3, 4, 5] print(last) âžž outputs 6 With Python 3, you can assign variables from lists in a much more succinct way. Create variables first, middle and last from the given list using destructuring assignment (check the Resources tab for some examples), where: first âžž 1

middle âžž [2, 3, 4, 5]

last âžž 6 Your task is to unpack the list writeyourcodehere into three variables, being first, middle, and last, with middle being everything in between the first and last element. Then print all three variables.

  1. Write a function that calculates the factorial of a number recursively. Examples factorial(5) âžž 120

factorial(3) âžž 6

factorial(1) âžž 1

factorial(0) âžž 1

  1. Write a function that moves all elements of one type to the end of the list. Examples move_to_end([1, 3, 2, 4, 4, 1], 1) âžž [3, 2, 4, 4, 1, 1]

Move all the 1s to the end of the array.

move_to_end([7, 8, 9, 1, 2, 3, 4], 9) âžž [7, 8, 1, 2, 3, 4, 9]

move_to_end(["a", "a", "a", "b"], "a") âžž ["b", "a", "a", "a"]

Programming_Assingment19

  1. Create a function that takes a string and returns a string in which each character is repeated once. Examples double_char("String") âžž "SSttrriinngg"

double_char("Hello World!") âžž "HHeelllloo WWoorrlldd!!"

double_char("1234!_ ") âžž "11223344!!__ "

  1. Create a function that reverses a boolean value and returns the string "boolean expected" if another variable type is given. Examples reverse(True) âžž False

reverse(False) âžž True

reverse(0) âžž "boolean expected"

reverse(None) âžž "boolean expected"

  1. Create a function that returns the thickness (in meters) of a piece of paper after folding it n number of times. The paper starts off with a thickness of 0.5mm. Examples num_layers(1) âžž "0.001m"

Paper folded once is 1mm (equal to 0.001m)

num_layers(4) âžž "0.008m"

Paper folded 4 times is 8mm (equal to 0.008m)

num_layers(21) âžž "1048.576m"

Paper folded 21 times is 1048576mm (equal to 1048.576m)

  1. Create a function that takes a single string as argument and returns an ordered list containing the indices of all capital letters in the string. Examples index_of_caps("eDaBiT") âžž [1, 3, 5]

index_of_caps("eQuINoX") âžž [1, 3, 4, 6]

index_of_caps("determine") âžž []

index_of_caps("STRIKE") âžž [0, 1, 2, 3, 4, 5]

index_of_caps("sUn") âžž [1]

  1. Using list comprehensions, create a function that finds all even numbers from 1 to the given number. Examples find_even_nums(8) âžž [2, 4, 6, 8]

find_even_nums(4) âžž [2, 4]

find_even_nums(2) âžž [2]

Programming_Assingment20

  1. Create a function that takes a list of strings and integers, and filters out the list so that it returns a list of integers only. Examples filter_list([1, 2, 3, "a", "b", 4]) âžž [1, 2, 3, 4]

filter_list(["A", 0, "Edabit", 1729, "Python", "1729"]) âžž [0, 1729]

filter_list(["Nothing", "here"]) âžž []

  1. Given a list of numbers, create a function which returns the list but with each element's index in the list added to itself. This means you add 0 to the number at index 0, add 1 to the number at index 1, etc... Examples add_indexes([0, 0, 0, 0, 0]) âžž [0, 1, 2, 3, 4]

add_indexes([1, 2, 3, 4, 5]) âžž [1, 3, 5, 7, 9]

add_indexes([5, 4, 3, 2, 1]) âžž [5, 5, 5, 5, 5]

  1. Create a function that takes the height and radius of a cone as arguments and returns the volume of the cone rounded to the nearest hundredth. See the resources tab for the formula.

Examples cone_volume(3, 2) âžž 12.57

cone_volume(15, 6) âžž 565.49

cone_volume(18, 0) âžž 0

  1. This Triangular Number Sequence is generated from a pattern of dots that form a triangle. The first 5 numbers of the sequence, or dots, are: 1, 3, 6, 10, 15 This means that the first triangle has just one dot, the second one has three dots, the third one has 6 dots and so on. Write a function that gives the number of dots with its corresponding triangle number of the sequence. Examples triangle(1) âžž 1

triangle(6) âžž 21

triangle(215) âžž 23220

  1. Create a function that takes a list of numbers between 1 and 10 (excluding one number) and returns the missing number. Examples missing_num([1, 2, 3, 4, 6, 7, 8, 9, 10]) âžž 5

missing_num([7, 2, 3, 6, 5, 9, 1, 4, 8]) âžž 10

missing_num([10, 5, 1, 2, 4, 6, 8, 3, 9]) âžž 7

Programming_Assingment21

  1. Write a function that takes a list and a number as arguments. Add the number to the end of the list, then remove the first element of the list. The function should then return the updated list. Examples next_in_line([5, 6, 7, 8, 9], 1) âžž [6, 7, 8, 9, 1]

next_in_line([7, 6, 3, 23, 17], 10) âžž [6, 3, 23, 17, 10]

next_in_line([1, 10, 20, 42 ], 6) âžž [10, 20, 42, 6]

next_in_line([], 6) âžž "No list has been selected"

  1. Create the function that takes a list of dictionaries and returns the sum of people's budgets. Examples get_budgets([ { "name": "John", "age": 21, "budget": 23000 }, { "name": "Steve", "age": 32, "budget": 40000 }, { "name": "Martin", "age": 16, "budget": 2700 } ]) âžž 65700

get_budgets([ { "name": "John", "age": 21, "budget": 29000 }, { "name": "Steve", "age": 32, "budget": 32000 }, { "name": "Martin", "age": 16, "budget": 1600 } ]) âžž 62600

  1. Create a function that takes a string and returns a string with its letters in alphabetical order. Examples alphabet_soup("hello") âžž "ehllo"

alphabet_soup("edabit") âžž "abdeit"

alphabet_soup("hacker") âžž "acehkr"

alphabet_soup("geek") âžž "eegk"

alphabet_soup("javascript") âžž "aacijprstv" 4. Suppose that you invest $10,000 for 10 years at an interest rate of 6% compounded monthly. What will be the value of your investment at the end of the 10 year period? Create a function that accepts the principal p, the term in years t, the interest rate r, and the number of compounding periods per year n. The function returns the value at the end of term rounded to the nearest cent. For the example above: compound_interest(10000, 10, 0.06, 12) âžž 18193.97 Note that the interest rate is given as a decimal and n=12 because with monthly compounding there are 12 periods per year. Compounding can also be done annually, quarterly, weekly, or daily. Examples compound_interest(100, 1, 0.05, 1) âžž 105.0

compound_interest(3500, 15, 0.1, 4) âžž 15399.26

compound_interest(100000, 20, 0.15, 365) âžž 2007316.26

  1. Write a function that takes a list of elements and returns only the integers. Examples return_only_integer([9, 2, "space", "car", "lion", 16]) âžž [9, 2, 16]

return_only_integer(["hello", 81, "basketball", 123, "fox"]) âžž [81, 123]

return_only_integer([10, "121", 56, 20, "car", 3, "lion"]) âžž [10, 56, 20, 3]

return_only_integer(["String", True, 3.3, 1]) âžž [1]

Programming_Assingment22

  1. Create a function that takes three parameters where: • x is the start of the range (inclusive). • y is the end of the range (inclusive). • n is the divisor to be checked against. Return an ordered list with numbers in the range that are divisible by the third parameter n. Return an empty list if there are no numbers that are divisible by n. Examples list_operation(1, 10, 3) ➞ [3, 6, 9]

list_operation(7, 9, 2) âžž [8]

list_operation(15, 20, 7) âžž []

  1. Create a function that takes in two lists and returns True if the second list follows the first list by one element, and False otherwise. In other words, determine if the second list is the first list shifted to the right by 1. Examples simon_says([1, 2], [5, 1]) âžž True

simon_says([1, 2], [5, 5]) âžž False

simon_says([1, 2, 3, 4, 5], [0, 1, 2, 3, 4]) âžž True

simon_says([1, 2, 3, 4, 5], [5, 5, 1, 2, 3]) ➞ False Notes • Both input lists will be of the same length, and will have a minimum length of 2. • The values of the 0-indexed element in the second list and the n-1th indexed element in the first list do not matter.

  1. A group of friends have decided to start a secret society. The name will be the first letter of each of their names, sorted in alphabetical order. Create a function that takes in a list of names and returns the name of the secret society. Examples society_name(["Adam", "Sarah", "Malcolm"]) âžž "AMS"

society_name(["Harry", "Newt", "Luna", "Cho"]) âžž "CHLN"

society_name(["Phoebe", "Chandler", "Rachel", "Ross", "Monica", "Joey"])

  1. An isogram is a word that has no duplicate letters. Create a function that takes a string and returns either True or False depending on whether or not it's an "isogram". Examples is_isogram("Algorism") âžž True

is_isogram("PasSword") âžž False

Not case sensitive.

is_isogram("Consecutive") ➞ False Notes • Ignore letter case (should not be case sensitive). • All test cases contain valid one word strings.

  1. Create a function that takes a string and returns True or False, depending on whether the characters are in order or not. Examples is_in_order("abc") âžž True

is_in_order("edabit") âžž False

is_in_order("123") âžž True

is_in_order("xyzz") âžž True Notes You don't have to handle empty strings.

Programming_Assingment23

  1. Create a function that takes a number as an argument and returns True or False depending on whether the number is symmetrical or not. A number is symmetrical when it is the same as its reverse. Examples is_symmetrical(7227) âžž True

is_symmetrical(12567) âžž False

is_symmetrical(44444444) âžž True

is_symmetrical(9939) âžž False

is_symmetrical(1112111) âžž True

  1. Given a string of numbers separated by a comma and space, return the product of the numbers. Examples multiply_nums("2, 3") âžž 6

multiply_nums("1, 2, 3, 4") âžž 24

multiply_nums("54, 75, 453, 0") âžž 0

multiply_nums("10, -2") âžž -20

  1. Create a function that squares every digit of a number. Examples square_digits(9119) âžž 811181

square_digits(2483) âžž 416649

square_digits(3212) âžž 9414 Notes The function receives an integer and must return an integer.

  1. Create a function that sorts a list and removes all duplicate items from it. Examples setify([1, 3, 3, 5, 5]) âžž [1, 3, 5]

setify([4, 4, 4, 4]) âžž [4]

setify([5, 7, 8, 9, 10, 15]) âžž [5, 7, 8, 9, 10, 15]

setify([3, 3, 3, 2, 1]) âžž [1, 2, 3]

  1. Create a function that returns the mean of all digits. Examples mean(42) âžž 3

mean(12345) âžž 3

mean(666) ➞ 6 Notes • The mean of all digits is the sum of digits / how many digits there are (e.g. mean of digits in 512 is (5+1+2)/3(number of digits) = 8/3=2). • The mean will always be an integer.

Programming_Assingment24

  1. Create a function that takes an integer and returns a list from 1 to the given number, where:
  2. If the number can be divided evenly by 4, amplify it by 10 (i.e. return 10 times the number).
  3. If the number cannot be divided evenly by 4, simply return the number. Examples amplify(4) âžž [1, 2, 3, 40]

amplify(3) âžž [1, 2, 3]

amplify(25) ➞ [1, 2, 3, 40, 5, 6, 7, 80, 9, 10, 11, 120, 13, 14, 15, 160, 17, 18, 19, 200, 21, 22, 23, 240, 25] Notes • The given integer will always be equal to or greater than 1. • Include the number (see example above). • To perform this problem with its intended purpose, try doing it with list comprehensions. If that's too difficult, just solve the challenge any way you can.

  1. Create a function that takes a list of numbers and return the number that's unique. Examples unique([3, 3, 3, 7, 3, 3]) âžž 7

unique([0, 0, 0.77, 0, 0]) âžž 0.77

unique([0, 1, 1, 1, 1, 1, 1, 1]) âžž 0 Notes Test cases will always have exactly one unique number while all others are the same.

  1. Your task is to create a Circle constructor that creates a circle with a radius provided by an argument. The circles constructed must have two getters getArea() (PIr^2) and getPerimeter() (2PI*r) which give both respective areas and perimeter (circumference). For help with this class, I have provided you with a Rectangle constructor which you can use as a base example. Examples circy = Circle(11) circy.getArea()

Should return 380.132711084365

circy = Circle(4.44) circy.getPerimeter()

Should return 27.897342763877365

Notes Round results up to the nearest integer.

  1. Create a function that takes a list of strings and return a list, sorted from shortest to longest. Examples sort_by_length(["Google", "Apple", "Microsoft"]) âžž ["Apple", "Google", "Microsoft"]

sort_by_length(["Leonardo", "Michelangelo", "Raphael", "Donatello"]) âžž ["Raphael", "Leonardo", "Donatello", "Michelangelo"]

sort_by_length(["Turing", "Einstein", "Jung"]) âžž ["Jung", "Turing", "Einstein"] Notes All test cases contain lists with strings of different lengths, so you won't have to deal with multiple strings of the same length.

  1. Create a function that validates whether three given integers form a Pythagorean triplet. The sum of the squares of the two smallest integers must equal the square of the largest number to be validated.

Examples is_triplet(3, 4, 5) âžž True

3² + 4² = 25

5² = 25

is_triplet(13, 5, 12) âžž True

5² + 12² = 169

13² = 169

is_triplet(1, 2, 3) âžž False

1² + 2² = 5

3² = 9

Notes Numbers may not be given in a sorted order.

Programming_Assingment25

  1. Create a function that takes three integer arguments (a, b, c) and returns the amount of integers which are of equal value. Examples equal(3, 4, 3) âžž 2

equal(1, 1, 1) âžž 3

equal(3, 4, 1) âžž 0 Notes Your function must return 0, 2 or 3.

  1. Write a function that converts a dictionary into a list of keys-values tuples. Examples dict_to_list({ "D": 1, "B": 2, "C": 3 }) âžž [("B", 2), ("C", 3), ("D", 1)]

dict_to_list({ "likes": 2, "dislikes": 3, "followers": 10 }) âžž [("dislikes", 3), ("followers", 10), ("likes", 2)] Notes Return the elements in the list in alphabetical order.

  1. Write a function that creates a dictionary with each (key, value) pair being the (lower case, upper case) versions of a letter, respectively. Examples mapping(["p", "s"]) âžž { "p": "P", "s": "S" }

mapping(["a", "b", "c"]) âžž { "a": "A", "b": "B", "c": "C" }

mapping(["a", "v", "y", "z"]) âžž { "a": "A", "v": "V", "y": "Y", "z": "Z" } Notes All of the letters in the input list will always be lowercase.

  1. Write a function, that replaces all vowels in a string with a specified vowel. Examples vow_replace("apples and bananas", "u") âžž "upplus und bununus"

vow_replace("cheese casserole", "o") âžž "chooso cossorolo"

vow_replace("stuffed jalapeno poppers", "e") âžž "steffed jelepene peppers" Notes All words will be lowercase. Y is not considered a vowel.

  1. Create a function that takes a string as input and capitalizes a letter if its ASCII code is even and returns its lower case version if its ASCII code is odd. Examples ascii_capitalize("to be or not to be!") âžž "To Be oR NoT To Be!"

ascii_capitalize("THE LITTLE MERMAID") âžž "THe LiTTLe meRmaiD"

ascii_capitalize("Oh what a beautiful morning.") âžž "oH wHaT a BeauTiFuL moRNiNg."

About

This repository contains the Basic coding Assignments of Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published