intro to programming - syntax from chp 2

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

5 Terms

1
New cards

Output with print()

  • Use to display text or variables

  • Combine text and variables with commas

  • Customize output with or blank lines

2
New cards

Input with input()

  • input() gets user input as a string

  • Wrap with int() or float() to convert to numbers

  • Example: age = int(input("Enter age: "))

3
New cards

Expressions and Operators

  • Arithmetic: +, -, *, /

  • Exponentiation: **

  • Integer division: //

  • Modulus (remainder): %

  • Operator precedence follows math rules (PEMDAS)

4
New cards

Assignment Statements

  • Assign values with =

  • Reassign variables anytime

  • Swap values: x, y = y, x

  • Simultaneous assignment is allowed

5
New cards

Definite Loops with for

  • Loop runs a fixed number of times

  • Use range(n) for counting

  • Loop variable can be named or _ if unused

  • Example: for _ in range(3): print("Repeat")