## Python practice programs for beginners - Day 10

Day 9 Solution:

Day 10:  If-Else statement

In the above, we have used two if statements but we can reduce the number of lines of code by using an else statement.

You can see the number of lines of code decreased.

The If else get applied in many scenarios.

Get a number from the user and find whether the given number is an odd number or an even number.

## Python practice programs for beginners - Day9

Day 8 solution:

 Program

x and y is False
x or y is True
not x is False
Solution

Day 9:

if statement:

Syntax:

if condition:
#Statements to be executed once the condition is True

Example:

number=10

if  number>0:
print("The number is positive")

Output:
The number is positive

Try to get two single-digit numbers from the user then add the two numbers and if the addition of those two numbers is above 10 then print "You score greater than 10". If the addition is below 10 then print "You score less than 10".

Will see the solution in next post.

## Python practice programs for beginners - Day8

Day 7 Solutions:

a=int(input("Enter the number: "))
b=int(input("Enter the number: "))
print(f'{a} is greater than ">" {b} True or False? Result:{a>b}')
print(f'{a} is Lesser than "<" {b} True or False? Result:{a<b}')
print(f'{a} is equals to "==" {b} True or False? Result:{a==b}')
print(f'{a} is not equals to "!=" {b} True or False? Result:{a!=b}')
print(f'{a} is greater than or equals to ">=" {b} True or False? Result:{a>=b}')
print(f'{a} is lesser than or equals to "<=" {b} True or False? Result:{a<=b}')

Output:

Enter the number: 4
Enter the number: 4
4 is greater than ">" 4 True or False? Result: False
4 is Lesser than "<" 4 True or False? Result: False
4 is equal to "==" 4 True or False? Result: True
4 is not equal to "!=" 4 True or False? Result: False
4 is greater than or equals to ">=" 4 True or False? Result: True
4 is lesser than or equals to "<=" 4 True or False? Result: True

Day 8: Logical Operator

Logical Operators helps us to check more than one condition at a time.

we have 3 operators.

and - returns True when both operands return true else false

or - returns True if at least one of the operands is true.

not - returns True if the specified condition is not met.

and Operator:

Example:

a=10

b=10

c=10

a==b and a==c --> True

(True) and (True) --> True

a=11

b=10

c=10

a==b and a==c --> False

(False) and (True) --> False

or Operator:

a=11

b=10

c=10

a==b and a==c --> False

(False) and (True) --> True

not Operator:

not(b==c)

not(True) --> False

Task: Try to use these operators and check various conditions.

## Python practice programs for beginners - Day7

Day 6 Program:

### Output:

Day 7:

Relational Operators:

== --> Equals
!= --> Not Equals
> --> Greater than
< --> Lesser than
>= --> Greater than or equals
<= --> Lesser than or equals

Relational operators in python or comparison operators in python are used to find the relationship between 2 numbers/variables.

This expression will return Either True or False depending on the expression we use.

### Example:

a=10
b=20
a==b i.e  10==20

Output = False

Since 10 and 20 are not equals we get the result as False.

Try out all the relational operators along with the string formatting concept learned on Day 6.

### Example:

The output will be displayed in the next post.

## Python practice programs for beginners - Day6

Welcome to the 30-day challenge of Python practising for beginners.

### Day 5 practice program:

Practice all the Arithmetic Operators given:

### Arithemtic Operators:

Subtraction --> -
Multiplication --> *
Division (Quotient) --> /
Division (Remainder) --> %
Exponentiation --> **
Floor Division --> //

### Day 6:Formatting:

In the above output, you can see the output are getting displayed but it is not that clear to the user.

So we will use String formatting.

### Output:

Try to apply the formatting to all the other arithmetic operators.

The output will be displayed in the next post.

## Python practice programs for beginners - Day5

Welcome to the 30-day challenge of Python practising for beginners.

Day 4 practice program:

The solution is similar to that of the sample program discussed.

### Operators:

Operators are something that helps us to work with operands.
There are more operators in python.
In this post, we will try to learn the Arithmetic operator.

Arithemtic Operators:

Subtraction --> -
Multiplication --> *
Division (Quotient) --> /
Division (Remainder) --> %
Exponentiation --> **
Floor Division --> //

Example:

a=int(input("Enter the number"))
b=int(input("Enter the number"))
print(a+b)

Output:

### Day 5 Practice:

Practice all the Arithmetic Operators given above.

The output will be displayed in the next post.

## Python practice programs for beginners - Day4

Welcome to the 30-day challenge of Python practising for beginners.

Day 3 practice program:

Day 3 Solution:

Program:

Solution:

### Day 4:

Type Casting:

In the above example if you have noticed we got 2 inputs from the user.

Name and Age, where name is a String and Age is a number but in the above output, you can see that is also String.

To convert one type of data into another type we need to do Type Casting.

Syntax:

type_name(variable)

Example:

Program:

Output:

So after typecasting, you can see that the type of Age variable is int which is a number.

### Practice Program Day 4:

Write a program:

--> Get different data about a person

--> Find the type of data getting stored

--> Try to change the type of a variable and print it

The output will be displayed in the next post.

## Python practice programs for beginners - Day3

Welcome to the 30-day challenge of Python practising for beginners.

Day 2 Practice Program:

Day 2 Solution:

Program:

Output:

### Get Input from user:

So far, we have given the value to the variable in coding itself. Now we will try to get the input from the user at run time.

use input() function to get the input.

Program:

Output:

Practice program 3:

Try to use this input() to the previous program and provide the input at the run time.

--> Get the input from the user

--> Print the values

--> Print the type of variables.

The output will be displayed in the next post.

## Python practice programs for beginners - Day2

Welcome to the 30-day challenge of Python practising for beginners.

Day 1 Practice Program:

### Data types:

In the previous post, we practised variables. In this post, we will practice data types.

The type of data we are storing in the variable is called Data type.

Text kind of data is called as String, whole numbers such 5, 10 are called as Integers. Decimal valued data are called the float. True or False kinds of data are called Boolean.

to check the type of your data stored in the variable you can use type(variable_name) inside the print function.

Example:

Output:

### Practice Program - Day 2

Find the different types of data for the Day 1 program.

Also try to use Float, Boolean.

The output will be displayed in the next post.

## Python practice programs for beginners - Day1

Welcome to the 30-day challenge of Python practising for beginners.

Python practice programs for beginners - Day1

### Variables:

Variables are the most important concept in any programming language. It will help to store any data which we can use throughout the program.

userName is the variable name and "millioninformations" is the value stored in that variable.

### Rules for declaring Variables:

2. Should not contain space or special characters.
3. Underscore can be used to connect two words
4. Also can follow camelCase (first words first letter in lower case and second words first letter in upper case)

### Practice Program - Day 1

Write a Program to store a Student's details using the below variable names:

--> studentName
--> studentAge
--> studentGender
--> institute