/python_fundamentals

This is a answers repository for python fundamentals problem sheet

Primary LanguagePython

Python Fundamentals

This repository stores python scripts that answers fundamental python problems for Emerging Technologies module in my 4th year Bachelor level 8 degree.

Problem sheet is composed of 10 questions to be answered using Python language and demonstrate basic toolkit this programming language offers.

How to run scripts

Python scripts are considered to be a files with a .py extension.

To run a particulat python script, navigate to a script location in your file system and run the command: python my-script.py or py my-script.py

1. Hello, World

Write a program that prints “Hello, world!” to the screen.

Solution

2. Current Time

Write a program that prints the current time and date to the console.

Solution

3. Fizz Buzz

Write a program that prints the numbers from 1 to 100, except for the following conditions. For multiples of three print “Fizz” instead of the number, and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Solution

4. Factorial Digit Sum Function

Write a function that calculates the sum of the digits of the factorial of a number. n! means n x (n − 1) … x 3 x 2 x 1. For example, 10! = 10 x 9 x … x 3 x 2 x 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits in the number 100!

Solution

5. Guessing game

Write a guessing game where the user must guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.

Solution

6. Largest and smallest in list

Write a function that returns the largest and smallest elements in a list.

Solution

7. Palindrome test

Write a function that tests whether a string is a palindrome. Palindrome string considered to be a sequence of characters that can be read the same from both left and right. For example: 'asddsa' or 'asdfdsa'.

Solution

8. Merge list and sort

Write a function that merges two sorted lists into a new sorted list. [1,4,6],[2,3,5] → [1,2,3,4,5,6].

Solution

9. 9. Newton’s method for square roots

Implement the square root function using Newton’s method. In this case, Newton’s method is to approximate sqrt(x) by picking a starting point z and then repeating:

z_next = z - ((z*z - x) / (2 * z))

10. Reverse string

Write a function to reverse a string.