0% found this document useful (0 votes)
4 views6 pages

Python Day5 String Math Random

The document provides class notes for Day 5 of a Python for Kids course, covering string, math, and random programs. It includes various examples of string manipulation, mathematical operations, and random number generation using Python code. Each section contains concise code snippets demonstrating different functionalities and methods available in Python.

Uploaded by

Madhu Mitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Day5 String Math Random

The document provides class notes for Day 5 of a Python for Kids course, covering string, math, and random programs. It includes various examples of string manipulation, mathematical operations, and random number generation using Python code. Each section contains concise code snippets demonstrating different functionalities and methods available in Python.

Uploaded by

Madhu Mitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python for Kids - Day 5: String | Math | Random

Python for Kids


DAY 5 - Class Notes
String Programs | Math Programs | Random Programs

STRING Programs

▶ String Programs

01. Print String 02. Length of String


text = "Hello" name = "Python"
print(text) print(len(name))

03. Uppercase 04. Lowercase


word = "python" word = "PYTHON"
print([Link]()) print([Link]())

05. Capitalize 06. Title Case


text = "hello" text = "python
print([Link]() programming"
) print([Link]())

07. Replace Word 08. Concatenate Strings


text = "I like Java" a = "Hello "
print([Link]("Jav b = "World"
a", "Python")) print(a + b)

09. Repeat String 10. Reverse String


word = "Hi " text = "Python"
print(word * 3) print(text[::-1])
Page 1
Python for Kids - Day 5: String | Math | Random

11. Check Substring 12. Count Character


text = "Python text = "banana"
Programming" print([Link]("a"))
print("Python" in text)

13. Find Position 14. Split String


text = "Python" text = "apple banana
print([Link]("h")) mango"
print([Link]())

15. Join Strings 16. Remove Spaces


words = ["Python", text = " hello "
"Java", "C"] print([Link]())
print("-".join(words))

17. Startswith 18. Endswith


text = "Python" text = "Python"
print([Link](" print([Link]("o
Py")) n"))

19. Check Alphabet 20. Check Digit


text = "Python" text = "12345"
print([Link]()) print([Link]())

MATH Programs

▶ Math Programs

Page 2
Python for Kids - Day 5: String | Math | Random

01. Addition 02. Subtraction


a = 10 a = 20
b = 5 b = 8
print(a + b) print(a - b)

03. Multiplication 04. Division


a = 6 a = 25
b = 7 b = 5
print(a * b) print(a / b)

05. Floor Division 06. Modulus


print(17 // 5) print(17 % 5)

07. Power 08. Square Root


print(2 ** 4) import math
print([Link](36))

09. Maximum Number 10. Minimum Number


print(max(10, 50, 20)) print(min(10, 50, 20))

11. Absolute Value 12. Round Number


print(abs(-25)) print(round(5.678, 2))

13. Ceiling Value 14. Floor Value


import math import math
print([Link](5.2)) print([Link](5.9))

15. Factorial 16. GCD


import math import math
print([Link](5)) print([Link](12,
18))

Page 3
Python for Kids - Day 5: String | Math | Random

17. Sine Value 18. Cosine Value


import math import math
print([Link](0)) print([Link](0))

19. Log Value 20. Pi Value


import math import math
print([Link](10)) print([Link])

RANDOM Programs

▶ Random Programs

01. Random Integer 02. Random Float


import random import random
print([Link](1, print([Link]())
10))

03. Random Choice 04. Shuffle List


import random import random
colors = ["red", nums = [1, 2, 3, 4]
"blue", "green"] [Link](nums)
print([Link](col print(nums)
ors))

05. Random Even Number 06. Dice Roll


import random import random
print([Link]( print([Link](1,
2, 20, 2)) 6))

Page 4
Python for Kids - Day 5: String | Math | Random

07. Coin Toss 08. OTP Generator


import random import random
print([Link](["H print([Link](10
ead", "Tail"])) 00, 9999))

09. Lottery Number 10. Random Character


import random import random
print([Link](ran letters = "abcdef"
ge(1, 50), 5)) print([Link](let
ters))

11. Random Boolean 12. Random Negative No.


import random import random
print([Link]([Tr print([Link](-
ue, False])) 10, -1))

13. Random Odd Number 14. Pick Random Name


import random import random
print([Link]( names = ["Ram", "Sam",
1, 20, 2)) "Ravi"]
print([Link](nam
es))

15. Random Decimal 16. Password Generator


import random import random
print(round([Link] chars = "abc123"
orm(1, 10), 2)) print([Link](cha
rs))

17. Random Card 18. Random Month


import random import random
cards = ["King", months = ["Jan", "Feb",
"Queen", "Ace"] "Mar"]
print([Link](car print([Link](mon
Page 5
Python for Kids - Day 5: String | Math | Random

ds)) ths))

19. Random Color 20. Random Temperature


import random import random
colors = ["Red", print([Link](20
"Green", "Blue"] , 40))
print([Link](col
ors))

Happy Coding! - CSC Institute

Page 6

You might also like