[go: up one dir, main page]

0% found this document useful (0 votes)
116 views30 pages

1 Computational Thinking and Programming - 1.6

Uploaded by

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

1 Computational Thinking and Programming - 1.6

Uploaded by

yugchotai1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

1 Computational thinking and

programming : -
1.6 - Software development and
testing

BY : YUG CHOTAI
Topics

• 1. Errors(Common errors) in Python


• 2.Scratch
1.Learning Scratch
Events

• When green flag clicked – start the program


• When key pressed – respond to arrow keys
• When I receive [message] – respond to broadcast
messages
Motion

• go to x: [ ] y: [ ] – place sprite at a specific position


• go to random position – move sprite to a random spot
• change x by [ ] – move horizontally
• change y by [ ] – move vertically
Looks

• show – make sprite visible


• hide – make sprite invisible
Variables

• Create variables (Points, Wait)


• set variable to [ ] – initialise a value
• change variable by [ ] – increase/decrease variable values
Sensing

• touching [sprite]? – detect collisions


Control

• forever – repeat actions without stopping


• if [condition] then – run code only if condition is true
• wait [ ] seconds – pause for a set time
Operators

• pick random [ ] to [ ] – generate random numbers


• = – compare values (e.g., Wait = 5)
Broadcasting

• broadcast [message] – send a signal to other sprites


Solving codes
Q1)
PART 2
ERROR’s In Python
Syntax Errors

• When Python code breaks language rules.


• Example: if x = 5: (should be ==)
• Example: print('Hello' (missing parenthesis)
Indentation Errors

• Python uses indentation for code blocks.


• Example: if True: (next line must be indented)
Name Errors

• Occurs when a variable or function name is not defined.


• Example: print(my_var) when my_var is not defined.
Type Errors

• Occurs when performing operations on incompatible


types.
• Example: 5 + 'hello' (cannot add int and str)
Value Errors

• Occurs when a function gets the right type but invalid


value.
• Example: int('abc') cannot convert 'abc' to integer.
ZeroDivisionError

• Occurs when dividing a number by zero.


• Example: 5 / 0
Index Errors

• Occurs when accessing a list index that does not exist.


• Example: my_list[5] when list has fewer elements.
Key Errors

• Occurs when accessing a dictionary key that does not


exist.
• Example: my_dict['b'] when 'b' is not a key.
QUESTIONS
QUESTION – Q1
• c = int(input("Enter first number: "))
• a= int(input("Enter second number: "))
• total=sum = num1 + num2
• print("The sum is:", total=sum)
ANS – Q1

• c = int(input("Enter first number: "))


• a= int(input("Enter second number: "))
• totalsum = a + c / totalsum = c + a
• print("The sum is:", totalsum)
Q2

• x = int(input("Enter value 1: "))


• y = int(input("Enter value 2: "))
• total = xy + zy
• print("Total:, Total)
ANS – Q2

• x = int(input("Enter value 1: "))


• y = int(input("Enter value 2: "))
• total = x + y
• print("Total:, total)

You might also like