telesko python 4
telesko python 4
Here are some of the most commonly used ones methods of math module:
Here are some of the most commonly used ones attributes(constant) of math module:
using help function we can get all the information about math module
help(math)
e.g
name = input("Please enter your name: ")
x=input("Enter first number: ");
y=input("Enter second number: ");
z=x+y;
print(z);
#2 input function
-- In Python, the input() function is used to accept user input from the command line or console.
name=input("Enter your name:");
print(name);
-- In this example, the input() function prompts the user to enter their name. Whatever the user types
in response is stored in the name variable.
-- Note that the input() function always returns a string, so if we want to use the user's input as a number,
we'll need to convert it using the appropriate type-casting function (e.g., int() for integers or float() for
floating-point numbers).
e.g
x=input("Enter first number: ");
a=int(x);
the input entered by the user is converted to an integer using the int() function in this example.
#5 eval function
eval function
-- The eval() function in Python is used to evaluate an expression entered by the user as a string.
e.g
x=eval(input("Enter an expression: "));
typeOf = type(x);
print(typeOf);
#6
Passing values from command line
-- sys module provides access to any command-line arguments via the sys.argv list.
we can pass arguments to a Python script from the command line using the sys.argv list.
The first argument in the list is always the name of the script itself.
#1
- CPU has three parts: CU (Control Unit), ALU ( Arithmetic Logic Unit) and MU ( Memory unit).
- MU is used to store variables and data.
- ALU has two parts:
1. AU - Arithmetic Unit ( it performs mathematical calculations)
2. LU - Logical Unit ( it makes a computer think something)
#2
If statement:-
- In programming, we have to apply conditions as per the logic of the code. In python, conditions can be applied
through the if keyword.
- Use of the if keyword specifies the flow of execution of the code.
- Based on the condition of the problem statement, if keyword helps to decide which set of statements should
be executed.
Syntax:-
if (condition):
statement;
- The statements of the if block will be executed only when the condition of the if statement is true. If the
condition is false then it will skip the execution of statements present inside the if block.
- If consists of a block where you can write multiple statements. In python, it is also known as Suite.
#2
Indentation:-
- In Python, we have to follow certain indentations that specify the conditions that are present inside a certain
block.
- Indentation simply means a certain number of spaces at the beginning of a code line.
- Indentation increases the readability of the code.
#3
Else block:-
- We can also use multiple if blocks in a code.
- Multiple uses of the if block decrease the efficiency of a code as the condition will be checked again and again
in each if block.
- To make the code efficient, we use the else block.
- If the condition of the if block is true then the else block will be skipped. And if the condition of the if block is
false then the else block will be checked and executed.
#4
Nested if and else statements:-
- Nested if and else statements are also allowed in Python.
- if statement can also be checked inside other if statement. This conditional statement is called a nested if
statement.
- In nested, the inner if condition will be checked only if the outer if condition is true and that helps to see
multiple conditions to be satisfied.
#5
if, elif and else statements:-
- elif stands for if-else.
- The if-elif statement is a shortcut of if..else chain.
- If the if condition s false, then the condition inside the elif will be checked and executed.
- While using if-elif statement at the end else block is added that will be executed when none of the above if-elif
statements is true.
#if True:
# print("Im right")
# if False:
# print("Im right")
# print("Bye")
#x=4
#r=x%2
#
# if r==0:
# print("Even")
# if x>5:
# print("Great")
# else:
# print("Not so great")
#
# else:
# print("Odd")
#
# print("Bye")
x=5
if x==1:
print("one")
elif(x==2):
print("Two")
elif(x==3):
print("Three")
elif(x==4):
print("Four")
else:
print("Wrong Input")