S.N | Problem Name | Solution |
---|---|---|
001 |
Write suitable arithmetic expressions for the displayed descriptions.
1. Sum of 21 and 62
2. Difference between 43 and 17
3. 36 mod 5
4. Sum of 6 and 4 multiplied by 10
5. 23 to the 5th power
6. Any expression that will result in 19 and which includes multiplication
7. Sum of 177 mod 4 and 223 mod 5
8. Difference between 3rd power of 14 and 3rd power of 13
9. Any expression that will result in 0, which does not include multiplication and contains at least 3 arithmetic operators.
10. Any expression that includes all six arithmetic operators, addition (+), subtraction (-),
multiplication (*), division (/), modulo (%) and power (**).
Python has an in-built function – type() to check the data type.
Example: How to use the function type() to check the data type of the number 3368.5:
1.At the Python prompt, enter type(3368.5).
2.Press Enter. The interpreter will return the text, which means 3368.5 is a float object.
Problem Statement
Now, it’s your turn. Verify the data type for each of the objects given below using the type() function:
1.55.50
2.6+4j
3."hello"
4.([1,2,3,4])
5.((1,2,3,4))
6.({1:"one", 2:"two", 3:"three"})
Write the code that will display the required result for the given dictionary.
villians={1:"magneto", 2:"Joker", 3:"Doctor Doom", 5:"Lex Luthor", 9:"Green Goblin", 6:"Loki"}
1.Display the length of the dictionary.
2.Display the key which has the least value.
3.Display the value of the key 9 as well as delete it simultaneously.
4.Display all the values in dictionary.
5.Delete all the elements in the dictionary while retaining the empty object.
Write a short program to help a customer.
What does the customer want?
A power bank which has a charging capacity of at least 10000 mAh and costs less than Rs. 3500.
What does the store have?
A power bank which is 20000 mAh costing Rs. 3400
Your Challenge
Write a program which compares the store's power bank with customer requirements and displays a suitable message.
Display, 'Yes, this power bank is for you!' if both the requirements are met.
Display 'No, this doesn't suit your needs.' if either condition is not met.
If you want, experiment with different values of capacity and cost to see if your code works for both situations.
Note: - Using comparison and logical operators
Write the donut program to accommodate multiple discount slabs using multiple if-else statements.
Assume that the price per donut is Rs. 105.50 and 36 were purchased.
Discount Slabs
Amount > Rs.10000, 10% Discount
Amount > Rs. 5000, 5% Discount
Amount > Rs. 2000, 2% Discount
Amount > Rs.1000, 1% Discount
Note: For every if else condition, you have to increase the indent.
Write a program to print the multiplication table of 16 upto 16 * 10 using the 'while' loop.
Additional Challenge: Instead of 16, can you make it into a user input number,
so that the program can generate the multiplication table for any number?
It's your chance to transform yourself into Harry Potter!
Define a function called IPotter which will replace the name Harry with your name in the following string:
Looking Slughorn straight in the eye, Harry leant forwards a little.
'I am the Chosen One. I have to kill Voldemort. I need that memory.'
'You are the Chosen One?'
'Of course I am,' said Harry calmly.
Help Pi write a function!
Pi is in a dilemma. He needs to borrow money from his sister but doesn't want to tell her exactly how much he needs.
Pi: "Hey sis. You're looking cool today!"
Sis:"What's up Pi…what do you want?"
Pi: "Umm, actually I am running short of cash…I need to pay my EMI and…"
Sis: "Yeah…yeah…how much?"
Pi: "Your wish sis…wait, let me write a function which can help you decide…"
Sis: "You and your programming! Make it quick."
Function Details
Pi wants anything between 7000 and 10000 rupees!
So help Pi write a function that will check whether the amount his sister offers to give him (variable, sis) is within the required range of rupees.
If the number less than 7000, show the message, "Ahem, can you rethink this number please?".
If the number is greater than 10000, show the message, "Wow sis! You are a queen".
If the number is within the range, show the message, "Cool, thanks sis! x rupees will certainly help."
Note: After you have written the required function, keep changing the value of the variable sis to check if your function works for different values.
Pi's nephew is visiting and wants to play ludo with him.
Nephew: "Where's the ludo board? I left it here last time…"
Pi: "Umm, did you look in that shelf?"
Nephew: "Oh..found it! Come on…let's play! I want red! Oh…where's the dice?
It's lost…no wonder mamma keeps saying you are careless! Ha..ha…"
Pi: "Stop laughing brat! Wait, I'll make a cool dice for you."
Program Details
1.Help Pi impress his nephew with a program that behaves like a pair of dice.
2.Write a basic program using the random module to generate two numbers in the range 1 to 6.
Program Details
1. Make a new 'gift' class from the existing 'product' class.
2. Override 'get_price' method to add wrapping charge of Rs. 100 in the price.
Note: Open solution to see existing 'product' class.
Program Details
Write a function that computes the volume of a sphere given its radius.
The Volume of a sphere is given as
Program Details
Write a Function that accepts a String and calculates the upper case and lower case letters.
Sample Input : Hello, I am using Github.
Sample Output :
No. of Upper Case Characters : 3
No. of Lower Case Characters : 16
Hint: Using .isupper() and .islower() string methods.
Program Details
Write a Python Function that takes a list and returns a new list with unique elements of the first list.
Sample Input : [1,1,1,1,2,2,3,3,3,3,4,5]
Sample Output : [1,2,3,4,5]
Program Details
Write a Python function to multiply all the numbers in a list.
Sample Input : [1,2,3,-4]
Sample Input : -24
Program Details
Write a Python function that checks whether a word or phrase is palindrome or not.
Note:- A palindrome is word, phrase, or sequence that reads the same backward as forward.
E.g.
Word - madam, kayak, racecar
Phrase - 'nurses run'
Hint :- Use .replace() method in a string to help out with dealing with spaces.
Program Details
Write a Python function that check whether a string is pangram or not.
(Assume the string passed in does not have any punctuation.)
Note:- Pangrams are words or sentences containing every letter of the alphabet at least once.
Examples:
Input : The quick brown fox jumps over the lazy dog
Output : True
Input : abcdefgxyz
Output : False
Hint :- Use .replace() method in a string to help out with dealing with spaces.
Program Details
Write a program to calculate power using recursion.
Sample Input : N = 4, P = 2
Sample Input : 16
Program Details
Write a program to check the strength of a password based on following conditions and
output the type of password as "Too short", "Weak", "Medium" or "Strong".
Conditions:
1) Password should be 8 characters long.
2) It should contain at least one uppercase and one lowercase letter.
3) It should contain one or more of these special characters: ~, !, @, #, $, %, ^, &, *
4) It should contain one or more digits in it.
The output is defined as:
If the first condition fails, then output = "Too short"
If only two conditions including first one is met, then output = "Weak"
If only three conditions including first one is met, then output = "Medium"
If all four conditions are met, then output = "Strong"
Program Details
Suppose you have an input string S with the letters A B C D in any sequence,
and another input string T which is to be matched inside S.
Near matches are also allowed - where one non-matching character is allowed in identifying a match.
Write a program to find the number of occurrences of T in S.
For example:
Given "AAABCADDBCDDA" and "ABC" as input, the output is 2.
If T's near match is not found within S, the output should be 0.
Program Details
A company has launched a new text editor that allows users to enter English letters, numbers and whitespaces only.
If a user attempts to enter any other type of character, it is counted as a miss.
Given a string of text, write an algorithm to help the developer detect the number of misses by a given user in the given input.
Input:
The input consists of a string textInput, representing the text that is entered in the text editor by the user.
Output:
Print an integer representing the number of misses by a given user in the given input.
Example:
Input:
aa a234bc@ sad$ hsagd^
Output:
3
Program Details
A pizza shop makes vegan pizzas as well as meat based pizzas. The customers place N orders at the shop and their order number gets printed on thier bill.
The shop displays K out of N both - vegan and meat based pizza orders on thier display screen at a single time.The pizza shop is very famous and receives many orders.
So to avoid confusion, the vegan pizza orders are displayed as a positive order number and the meat based pizza orders are displayed as a negative order number.
All the orders are delivered in the order in which they are displayed on the screen.Each time a displayed order is ready, it is then removed from the display screen and
the next order is added to the display at the end.
A couple has come to eat pizza with their child Billy. Billy is a very naughty child and to keep him busy,
his parents tell him to make a list of the first meat nased pizza order number present in each set of K orders displayed on the shop's display scrren.
Write an algorithm to help Billy make a list of the first meat based pizza order numbers displayed on the screen each time an order is delivered to a customer.
Input:
The first line of the input consists of two space-separated integers - numofOrders and size, representing the total number of orders placed (N) and the number
of orders displayed on the screen (K), respectively.
The second line consists of N space-separated integers representing the vegan pizza and meat based pizza order numbers of the orders placed by the customers.
Output:
Print a list of space-separated integers representing the first meat based pizza order of every K orders displayed on the screen each time an order is
delivered to a customer and print 0 it the screen does not display any meat based pizza order.
Constraints:
0 <= numofOrders <= 10^6
0 <= size <= numofOrders
-10^9 <= ordersNum <= 10^9; where orderNum represents the order numbers of the orders placed.
Example:
Input:
6,3
-11 -2 19 37 64 -18
Output:
-11 -2 0 -18
Explanation:
Step 1: At the time of the first display, the order numbers displayed are [-11,-2,19].
So, the first displayed meat based pizza order number is -11.
Step 2: At the time of the next display, the order numbers displayed are [-2,19,37].
So, the first displayed meat based pizza order number is -2.
Step 3: At the time of the next display, the order numbers displayed are [19,37,64].
Since no meat based pizza order is displayed, the output is 0.
Step 4: Similarly, at the time of the next display, the order numbers displayed are [37,64,-18].
So, the first displayed meat based pizza order number is -18.
So, the output is [-11,-2,0,-18].
Program Details
Create a bank account class that has two attributes:
> Owner
> Balance
and Two methods:
> Deposit
> Withdraw
Note: Withdrawals may not exceed the available balance.
Instantiate your class, make several deposits and withdrawals, and test to make sure to account can't be overdrawn.