cat and assignments notes, Exercises of Computer Programming

it provides description of the cat that was sat on by fellow students

Typology: Exercises

2022/2023

Uploaded on 12/12/2023

macloud-kamula
macloud-kamula ๐Ÿ‡ฐ๐Ÿ‡ช

1 document

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming is fun! Enjoy!
SCHOOL OF ENGINEERING AND TECHNOLOGY
BACHELOR OF TECHNOLOGY ELECTRONICS AND COMPUTER ENGINEERING
AND
BACHELOR OF TECHNOLOGY TELECOMMUNICATION ENGINEERING
CAT I
ECE 2423: APPLICATION PROGRAMMING
DATE: 16-10-2023 TIME: 1 Hour
a) Highlight three applications of application programming in the current world and also
in the future use. (3 Marks)
a. Smart Grids:
i. Smart grids use advanced electronics and software to optimize
electricity generation, distribution, and consumption, enhancing
efficiency and reliability.
b. Electric Vehicles (EVs):
i. EVs incorporate complex electrical systems and software to manage
power delivery, battery charging, and vehicle control, reducing carbon
emissions.
c. Home Automation Systems:
i. Smart home systems employ electronics and programming to automate
and control lighting, HVAC, security, and appliances for energy
efficiency and convenience.
d. Wearable Electronics:
i. Wearable devices, like fitness trackers and smartwatches, integrate
sensors and software to monitor health and collect data for user
insights.
e. Industrial Automation:
i. In manufacturing and industrial settings, automation systems leverage
electronics, sensors, and software to optimize production processes,
ensuring efficiency and quality.
Correct explanation earns full marks
b) Using a relevant Python code snippet, differentiate between the arithmetic operators
in Python: %, / and // (3 Marks)
i. % (Modulus Operator):
The modulus operator % calculates the remainder of a division operation. It returns
the remainder when one number is divided by another.
ii. / (Division Operator):
pf3
pf4
pf5

Partial preview of the text

Download cat and assignments notes and more Exercises Computer Programming in PDF only on Docsity!

SCHOOL OF ENGINEERING AND TECHNOLOGY

BACHELOR OF TECHNOLOGY ELECTRONICS AND COMPUTER ENGINEERING

AND

BACHELOR OF TECHNOLOGY TELECOMMUNICATION ENGINEERING

CAT I

ECE 2423: APPLICATION PROGRAMMING

DATE: 16 - 10 - 2023 TIME : 1 Hour a) Highlight three applications of application programming in the current world and also in the future use. (3 Marks) a. Smart Grids: i. Smart grids use advanced electronics and software to optimize electricity generation, distribution, and consumption, enhancing efficiency and reliability. b. Electric Vehicles (EVs): i. EVs incorporate complex electrical systems and software to manage power delivery, battery charging, and vehicle control, reducing carbon emissions. c. Home Automation Systems: i. Smart home systems employ electronics and programming to automate and control lighting, HVAC, security, and appliances for energy efficiency and convenience. d. Wearable Electronics: i. Wearable devices, like fitness trackers and smartwatches, integrate sensors and software to monitor health and collect data for user insights. e. Industrial Automation: i. In manufacturing and industrial settings, automation systems leverage electronics, sensors, and software to optimize production processes, ensuring efficiency and quality. Correct explanation earns full marks b) Using a relevant Python code snippet, differentiate between the arithmetic operators in Python: %, / and // ( 3 Marks) i. % (Modulus Operator): The modulus operator % calculates the remainder of a division operation. It returns the remainder when one number is divided by another. ii. / (Division Operator):

The division operator / performs regular division and returns a floating-point result (a decimal number). iii. // (Floor Division Operator): The floor division operator // also performs division but rounds down the result to the nearest whole number (integer division). It discards the decimal part. Each correct explanation earns two marks with a correct code snippet earns two marks. c) Explain the difference between a local variable and a global variable (2 Marks)

  • Global variables are defined at the top level of a Python script or module and can be accessed from any part of the code.
  • Local variables are defined within a function's scope and are only accessible within that function. They are created when the function is called and destroyed when the function exits. Correct code with proper explanation earns full marks d) What are Python data types? Provide examples of at least three different data types with their respective initialization ( 3 Marks) Integer (int) :
  • An integer data type represents whole numbers, both positive and negative, without any decimal point. Float (float):
  • A float data type represents floating-point numbers, which can have decimal points and fractions. String (str) :
  • A string data type represents a sequence of characters enclosed in single (' '), double (" "), or triple (''' ''' or """ """) quotes. Correct code with proper explanation earns one mark for each

Correct code with proper explanation earns full marks h) Using relevant programming languages examples, differentiate between compilers and interpreters. (4 Marks) Compilers and interpreters are both tools used in the field of programming to translate and execute code, but they do so in different ways. Translation Process :

  • A compiler translates the entire source code of a program into machine code or an intermediate code all at once, before execution.
  • The resulting compiled code is often saved to a separate file, which can be executed independently of the source code. Translation Process :
  • An interpreter translates and executes code line by line or statement by statement, as it encounters each instruction. Examples :
  • One of the classic examples of a compiled language is C/C++. In C, you write your code in a .c file and use a compiler like GCC to generate an executable file, which you can run without needing the original .c file. Examples :
  • Python is a popular interpreted language. You write your Python code in a .py file, and the Python interpreter reads and executes it line by line when you run the script. Correct explanation earns full marks i) How do you comment out code in Python, and why is commenting important? Using relevant code snippet, show two ways you can comment out Python code ( 4 Marks) Comments are placed using either # or โ€œโ€โ€ โ€œโ€โ€

Correct code with proper explanation earns full marks