Python Syntax II
Python Syntax: Variables
In Python, and when programming in general, we need to build systems for dealing with data that changes over time. That data could be the location of a plane, or the time of day, or the television show you’re currently watching. The only important thing is that it may be different at different times. Python uses variables to define things that are subject to change.
greeting_message = "Welcome to Codecademy!"
current_excercise = 5
In the above example, we defined a variable called greeting_message and set it equal to the string “Welcome to Codecademy!”. It also defined a variable called current_exercise and set it equal to the number 5.
Instructions
1. Create a variable called todays_date and assign a value that will represent today’s date to that variable.
Arithmetic
One thing computers are capable of doing exceptionally well is performing arithmetic. Addition, subtraction, multiplication, division, and other numeric calculations are easy to do in most programming languages, and Python is no exception. Some examples:
mirthful_addition = 12381 + 91817
amazing_subtraction = 981 - 312
trippy_multiplication = 38 * 902
happy_division = 540 / 45
sassy_combinations = 129 * 1345 + 120 / 6 - 12
Above are a number of arithmetic operations, each assigned to a variable. The variable will hold the final result of each operation. Combinations of arithmetical operators follow the usual order of operations.
Python also offers a companion to division called the modulo operator. The modulo operator is indicated by % and returns the remainder after division is performed.
is_this_number_odd = 15 % 2
is_this_number_divisible_by_seven = 133 % 7
In the above code block, we use the modulo operator to find the remainder of 15 divided by 2. Since 15 is an odd number the remainder is 1.
We also check the remainder of 133 / 7. Since 133 divided by 7 has no remainder, 133 % 7 evaluates to 0.
Instructions
1. Multiply two numbers together and assign the result to a variable called product.
2. What is the remainder when 1398 is divided by 11? Save the results in a variable called remainder.
todays_date = “28 april”
ОтветитьУдалитьtodays_date = "04.28.2025"
ОтветитьУдалитьKanaev ISIP 3
Удалитьtodays_date = “April 28, 2025”
ОтветитьУдалитьtodays_date = "Today is April 28, 2025"
ОтветитьУдалитьOsmanova A.
todays_date = "28.04.2025"
ОтветитьУдалитьАшура
todays_date = "April 28, 2025"
ОтветитьУдалитьtodays_date = "April 28, 2025"
ОтветитьУдалить1. product = 10 * 8
ОтветитьУдалить1. product = 10 * 8
ОтветитьУдалитьa = int(unput())
ОтветитьУдалитьb = int(input())
product = a * b
print(product)
product = 1 * 2
ОтветитьУдалитьremainded = 1398 % 11
product = 5 * 7
ОтветитьУдалитьAshura
Удалитьremainder = 1398 % 11
ОтветитьУдалить2. remainder = 1398 % 11
ОтветитьУдалить2. remainder = 1398 % 11
ОтветитьУдалитьproduct = 25 * 46
ОтветитьУдалитьremainder = 1398 % 11
1. product = 20 * 3
ОтветитьУдалить2. remainder = 1398%11
Osmanova A
remainder = 1398 % 11
ОтветитьУдалитьAshura
Удалить