Config VS code
String, input, Calculator, variable type, eval
str1 = "My first test string"
pos = int(input("Symbols: "))
print(pos, str1[0:pos])
Words counter
testString = input("Type the string: ")
counter = 1
# Loop string symbols
for i in range (len(testString)):
print (testString[i])
if (testString[i] == ' ' and testString[i+1] != ' ' ): counter += 1
print ("In the string: \"", testString, "\" we found ", counter)
even - odd check
a = 6
res = a%2
if (res == 0):
print ("Even")
else:
print ("Odd")
Introduce Array
data structure: array or list
print(1+2)
a = input("Input a: ")
b = input ("Input b: ")
#
print ("a+b = ", a+b)
print ("a+b = ", int(a)+float(b))
if, indents, blocks,
# if - indents
a = float(input("a: "))
b = float(input("b: "))
if (a < b): print ("a < b")
print ("11111111111111111111111111111111")
if (a < b):
print ("Compared a and b values:")
print ("a < b")
else:
print ("else statements")
print ("2222222222222222222222222222222222")
if (b % a == 0) :
print ("b is divisible by a")
elif (b + 1 == 10):
print ("Increment in b produces 10")
else:
print ("You are in else statement")
myDaysEn = ["Sunday", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
myDaysHe = ["יוֹם רִאשׁוֹן","יוֹם שֵׁנִי","יוֹם שְׁלִישִׁי","יום רביעי","יוֹם חֲמִישִׁי","יוֹם שִׁישִׁי","יום שבת"]
myDaysRu = ["Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота"]
print (myDaysRu)
print (myDaysEn)
print (myDaysHe)
myDaysEn = ["Sunday", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
myDaysHe = ["יוֹם רִאשׁוֹן","יוֹם שֵׁנִי","יוֹם שְׁלִישִׁי","יום רביעי","יוֹם חֲמִישִׁי","יוֹם שִׁישִׁי","יום שבת"]
myDaysRu = ["Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота"]
lang = input("Your language (1 - Heb, 2 - Rus, 3 - Eng): ")
dayNumber = 0
while (dayNumber < 1 or dayNumber > 7):
dayNumber = int(input("Number of day: (1 --- 7): "))
if (lang == '1'):
print (myDaysHe[dayNumber])
elif (lang == "2"):
print (myDaysRu[dayNumber])
elif (lang == "3"):
print (myDaysEn[dayNumber])
else:
print ("Language undefined")
Array (list), loops, for, Logical operators (), while
Python Conditions and If statements
Python supports the usual logical conditions from mathematics:
- Equals: a == b
- Not Equals: a != b
- Less than: a < b
- Less than or equal to: a <= b
- Greater than: a > b
- Greater than or equal to: a >= b
Arithmetic operators, Comparison operators, Logical operators
and, or, not
x = True
y = False
# Output: x and y is False
print('x and y is',x and y)
# Output: x or y is True
print('x or y is',x or y)
# Output: not x is False
print('not x is',not x)
students = ["Stud1", "Stud2", "Stud3"]
print (students[0])
print (students[1])
print (students[2])
print (len(students))
# for statements
for stud in students:
print (stud)
print ("--------------------")
for i in range(10):
print (i)
for i in range(len(students)):
print (students[i])
students = []
stud = ''
while (stud != 'end'):
print (stud)
stud = input("New student: ")
students.append(stud)
print("Students: ", students, "Count: ", len(students), "Type: ", type(students))
str1 = "My first test string"
while (1):
pos = int(input("Symbols: "))
print(pos, str1[0:pos])
students1 = ["Student1", "Student2",22, 33.33]
students2 = [
["Ivanov", 22, "WEB"],
["Haim", 29, "PHP"],
["Yossy", 32, "Python"]
]
print (students1)
print (students2)
nameToFind = input("Type student name: ")
for student in students2:
if (student[0] == nameToFind):
print ("Found record: \n", student, "\nName: ", student[0], "\nAge: ", student[1], "\nCourse: ", student[2])
break
else:
print ("Student not found")