.
Computer Science Practice Sheet
Introduction to Computer Science
Computer Science is the study of how computers work and how they can be used to solve problems. It involves understanding the principles behind how computers process information, and how to create software and systems that use these principles to solve problems.
What is a Computer?
A computer is an electronic device that can take input, process it, and produce output. It is made up of hardware (the physical components) and software (the instructions that tell the computer what to do).
What is a Programming Language?
A programming language is a set of instructions that can be used to create software. It is used to tell the computer what to do by using commands and logic.
What is Algorithm?
An algorithm is a set of instructions that can be used to solve a problem. It is a step-by-step process that takes input and produces output.
What is a Data Structure?
A data structure is a way of organizing data so that it can be used efficiently. It is used to store data in a way that makes it easy to access, modify, and search.
Practice Problems
Write a program that takes two numbers as input and calculates the sum of the two numbers.
Write a program that takes a string as input and prints out the number of characters in the string.
Write a program that takes two strings as input and determines if the two strings are anagrams of each other.
Write a program that takes a list of numbers as input and prints out the maximum number in the list.
Write a program that takes a list of numbers as input and sorts the list in ascending order.
Answer Key
1.
```
Program to calculate the sum of two numbers
Take two numbers as input
num1 = int(input(Enter first number:
))
num2 = int(input(Enter second number:
))
Calculate the sum
sum = num1 + num2
Print the result
print(The sum of the two numbers is:
, sum)
```
2.
```
Program to print the number of characters in a string
Take a string as input
string = input(Enter a string:
)
Calculate the length of the string
length = len(string)
Print the result
print(The number of characters in the string is:
, length)
```
3.
```
Program to determine if two strings are anagrams
Take two strings as input
string1 = input(Enter first string:
)
string2 = input(Enter second string:
)
Check if the strings are anagrams
if sorted(string1) == sorted(string2):
print(The two strings are anagrams.
)
else:
print(The two strings are not anagrams.
)
```
4.
```
Program to find the maximum number in a list
Take a list of numbers as input
list = [int(x) for x in input(Enter a list of numbers:
).split()]
Find the maximum number
max_num = max(list)
Print the result
print(The maximum number in the list is:
, max_num)
```
5.
```
Program to sort a list of numbers in ascending order
Take a list of numbers as input
list = [int(x) for x in input(Enter a list of numbers:
).split()]
Sort the list in ascending order
list.sort()
Print the result
print(The sorted list is:
, list)
```