❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayPERUMAL S

day -7 task

By: PERUMAL S
22 July 2024 at 17:44

i have completed my task please let me know if found any mistake in comment box

Write a function that takes a string and returns a new string consisting of its first and last character.

number="tamizhnadu"
number[0:10:9]

Write a function that reverses a given string.

number[-1:-11:-1]

Given a string, extract and return a substring from the 3rd to the 8th character (inclusive).

num1="inclusive"
num1[2:9]

Write a function that returns every second character from a given string.

num1[2:9:2]

Write a function that checks if a given string is a palindrome (reads the same backward as forward).

name="civic"
print(name[0:4+1])
print(name[-1:-6:-1])

Given an email address, extract and return the domain.

mail="dummy@gmail.com"
mail[6:]

Write a function that returns every third character from a given string.

mail="dummy@gmail.com"
mail[2:15:3]

Write a function that extracts and returns characters at even indices from a given string.

mail[2:15:2]

Write a function that skips every second character and then reverses the resulting string.

mail[-1:-16:-2]

Python Day 7

By: PERUMAL S
22 July 2024 at 15:12

learning

index

always use character inside of this [] box
message =("hello world")
index number start from (0,1,2,3......)

h e l l o w o r l d
0 1 2 3 4 5 6 7 8 9 (positive index)
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 (negative index)

it will possible to find out this position

code 1
message ="hello world"
message [5]
result: o
code 2
message [-1]
result: d

slicing

h e l l o w o r l d
0 1 2 3 4 5 6 7 8 9 (positive index)
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 (negative index)
start ----------------------------end (stop) (forward direction)
(stop)end----------------------------start (reverse direction)

we can spectate the words based on the character position

[0:9] #[start:stop:(step or direction)]

slicing possible forward direction and reverse direction

NOTE
while reverse direction must to be use step -1
e.g
[-1:-10;-1] result reverse of "dlrowolleh"
[9:1:-1] result reverse of "dlrowolleh

ref

Image description

TASK 3-Q2

By: PERUMAL S
18 July 2024 at 14:29

Write a program that takes an integer as input and checks if it is even or odd

a= int(input("type your number:"))
if ((a%2)==0):
print("your number is even:")
else:
print("your number is odd:")

Day -6 learning

By: PERUMAL S
17 July 2024 at 15:30

Hi today learned functions

below the picture five basic structure of function

Image description

example:1

def india_allience(con,dmk):
return con+dmk
con=10
dmk=30
india_allience(con,dmk)

result

40

example:2

def india_allience(con,dmk):
return con+dmk
con=10
dmk=30
print("40 ku",india_allience(con,dmk))

result

40 ku 40

Task-3 Qsn-5

By: PERUMAL S
16 July 2024 at 17:58

Create a program that takes three numbers as input and prints the largest of the three.

Ans

note i have added Loop

while True:
num1=int(input("enter a number 1:"))
num2=int(input("enter a number 2:"))
num3=int(input("enter a number 3:"))
if num2<=num1>=num3:
print ("biggest num is",num1)
elif num1<=num2>=num3:
print ("biggest num is",num2)
else:
print ("biggest num is",num3)

Task 3 Qsn-7

By: PERUMAL S
16 July 2024 at 17:55

Create a program that takes a person’s age as input and checks if they are eligible to vote (age 18 or older).

Ans

Name=input("enter your name:")
age=int(input("enter your age:"))

if age>=18:
print("you are eligible to vote")
else:
print("you are not eligible for vote")

Task 3 Qsn-9

By: PERUMAL S
16 July 2024 at 17:53

Create a program that calculates simple interest. Take the principal amount, rate of interest, and time period as input.

Ans

a=float(input("enter your total loan amount :"))
b=float(input("total months :"))
if (b>=1):
d=(b*(a*0.02))
result=(a+d)
print("your total paid amount",result)
print("intrest amount",d)

Task-3 Qsn 10

By: PERUMAL S
16 July 2024 at 17:51

Write a program that asks the user to enter a password. If the password is correct, print β€œAccess granted”; otherwise, print β€œAccess denied”.

Ans

save_password=input("save your password")
a=input("enter your password :")
if a==save_password:
print("access granted")
else:
print("access denied")

Python Day-4 learning

By: PERUMAL S
15 July 2024 at 16:56

Hi all

today we learned operators, conditions also we made simple calculator based on this function

codes

addition
Add=num1+num2

subtract
Add=num1-num2

multiple
Add=num1*num2

divide
Add=num1/num2

modules
Add=num1%num2

exponential
Add=num1**num2

loop (while)

if,elif,else Condition

*input method *
whatever put in inside of input it will converts as string

E.g
num1=input(enter a number)
if we want as valued number put use or convert as a int or Float

num1= int input(enter a number)

simple calculator code

while True:
print("simple calculator")
print("select operation")
print("1.add")
print("2.subtract")
print("3.multiply")
print("4.diveded")
print("5.modulas")
print("6.exponential")
choice=input("select operation 1/2/3/4/5/6/7:")
num1=float(input("enter a number 1:"))
num2=float(input("enter a number 2:"))
if choice== "1":
result = num1+num2
print("result is",result)
elif choice== "2":
result = num1-num2
print("result is",result)
elif choice== "3":
result = num1*num2
print("result is",result)
elif choice== "4":
result = num1/num2
print("result is",result)
elif choice== "5":
result = num1%num2
print("result is",result)
elif choice== "6":
result = num1**num2
print("result is",result)
else choice== "7":
break

Day -3 learning

By: PERUMAL S
10 July 2024 at 17:12

1. Numeric Types (int, float, complex)

a) 26-int (numbers)
b) 26.5-float (numbers with decimal)
c) 2+3i complex (real number+ imaginary number)

2. Text Type (strings)
a)""
b)''
c)"""
"""

3. Boolean Type (bool)
a) True
b) False

4. None Type (None)
None means its like nothing there is no value

5. How to check a data type ?

a) identify the data type below methods
E.g.
type(26) result = int
type (26.5) result = float
type (True) result = bool
type("Chennai") result= str

6. What is a variable ?
variable is nothing kind of bag here we can save or store or define the object

*7. How to define it *

type variable Name = value;
E.g.
name=chozhan (variable)
city=thanjavur (variable)

8. valid, invalid variables

A variable name cannot start with a number have a space in the name or contain special characters

9. assigning values

10. multiple assignment

in single cell will assign multiple variable
E.g
name,age,city=chozhan,3000,thanjavr

code: print(name,age,city)

result: chozhan,3000,thanjavr

11. unpacking
will update future

12. variable types
will update future

13. Constants
user can defined the value should not be change

e.g.
PI=3.14

TASK 3-Q2

By: PERUMAL S
18 July 2024 at 14:29

Write a program that takes an integer as input and checks if it is even or odd

a= int(input("type your number:"))
if ((a%2)==0):
print("your number is even:")
else:
print("your number is odd:")

Day -6 learning

By: PERUMAL S
17 July 2024 at 15:30

Hi today learned functions

below the picture five basic structure of function

Image description

example:1

def india_allience(con,dmk):
return con+dmk
con=10
dmk=30
india_allience(con,dmk)

result

40

example:2

def india_allience(con,dmk):
return con+dmk
con=10
dmk=30
print("40 ku",india_allience(con,dmk))

result

40 ku 40

Task-3 Qsn-5

By: PERUMAL S
16 July 2024 at 17:58

Create a program that takes three numbers as input and prints the largest of the three.

Ans

note i have added Loop

while True:
num1=int(input("enter a number 1:"))
num2=int(input("enter a number 2:"))
num3=int(input("enter a number 3:"))
if num2<=num1>=num3:
print ("biggest num is",num1)
elif num1<=num2>=num3:
print ("biggest num is",num2)
else:
print ("biggest num is",num3)

Task 3 Qsn-7

By: PERUMAL S
16 July 2024 at 17:55

Create a program that takes a person’s age as input and checks if they are eligible to vote (age 18 or older).

Ans

Name=input("enter your name:")
age=int(input("enter your age:"))

if age>=18:
print("you are eligible to vote")
else:
print("you are not eligible for vote")

Task 3 Qsn-9

By: PERUMAL S
16 July 2024 at 17:53

Create a program that calculates simple interest. Take the principal amount, rate of interest, and time period as input.

Ans

a=float(input("enter your total loan amount :"))
b=float(input("total months :"))
if (b>=1):
d=(b*(a*0.02))
result=(a+d)
print("your total paid amount",result)
print("intrest amount",d)

Task-3 Qsn 10

By: PERUMAL S
16 July 2024 at 17:51

Write a program that asks the user to enter a password. If the password is correct, print β€œAccess granted”; otherwise, print β€œAccess denied”.

Ans

save_password=input("save your password")
a=input("enter your password :")
if a==save_password:
print("access granted")
else:
print("access denied")

❌
❌