Please read the note carefully and try to solve the problem below:
Table of Contents:
- Assign
55to the variablexand print it in the console - change the value of variable to be
60 - add x by
10again and print the value.
Click to see the solution
- create a variable
xand assign any integer value in it - create a variable
yand assign any float value in it - try using function
type()for x and y to check its data type.
# Examples
type(x)
type(4.5)Click to see the solution
Create two variables first_name, and last_name and print the sentence in the format below:
"My name is John Doe"
- use
+operator to concatenate strings - use
format()method to achieve the same result - use f-strings to achieve the same result
- use
%sformatting method to achieve the same result
Click to see the solution
Assign a variable pi and assign value 3.14159265
- use formatting strings to show pi with 3 digits after the decimal
- use formatting strings to show pi with 2 digits after the decimal but allocate 10 spaces for the variable.
- use f-string to show the result in the following format:
"The value of PIE is 3.14" ( hint:
"%<a>.<b>f")
Click to see the solution
Use a function input() to input the the name and age from the command line and display the formatted text as instructed below:
- use
input()function to ask the name to the user. The console should show"What is your name?"to input the name - similarly ask the user to input the age and assign it to another variable.
- Show a sentence describing the user name and age using different formatting methods.
- hint: Output would be a sentence similar to
Hello 20 years old John!!.
- hint: Output would be a sentence similar to
Click to see the solution
Perform the addition operations between the following data types and check whether the code runs successfully or not:
intandint(Example:5 + 5)intandfloat(Example:5 + 5.5)floatandfloat(Example:5.5 + 5.5)strandstr(Example:'hello' + 'world')intandstr(Example:5 + 'hello')
Use different operations in python to find out the following:
- Square of 10
- 1020
- Integer division of 100 by 30
- What would be the remainder if 1289 is divided by 25? solve programmatically.
The following variables are assigned values as below:
x = 10
y = 12- Check if x is greater than y
- Check if y is greater than x
- check if x is greater than or equal to y
- check if y is greater than or equal to x
- Check if x becomes equal to y if x is added by 2
- Check if x is not equal to y after the previous operation
"If the weather is cloudy today and it rained yesterday, it will rain today".
Generate the logical operation for the statement above and evaluate the weather forecast for today.
Note: Change parameters to different values and see when the result changes
Use Identity and Membership operations to solve the following problems
-
check whether the number
12is an integer or not -
divide
100by12and check whether the number isfloator not -
suppose we have following lists:
x = [1,2,3,4,5] y = [1,2,3,4,5] z = x
- Is
xidentical toy? - Is
xidentical toz?
Solve problems programmatically and write the reasons why they are or are not identical with each other.
- Is
-
Suppose there are following animals in the zoo:
elephant,tiger,zebra,lion,wolf- Check programmatically whether
lionis in the zoo or not. - Check programmatically whether
horseis in the zoo or not.
- Check programmatically whether
-
Create a list of first 7 prime numbers and check whether 9 is a prime number or not using membership operation.
Use bitwise operations to perform the following:
- Check the final value when
5is performed bitwise AND with7 - Check the final value when
5is performed bitwise OR with2 y = 10 * 2. Solve the same problem using bitwise shift operation.- Multiply and divide an integer by 4 using bitwise shift operations.