0% found this document useful (0 votes)
9 views2 pages

Python Practice Problems Level 1.5-2

The document outlines a series of custom Python practice problems aimed at levels 1.5 to 2. It includes tasks such as counting digits without converting to string, checking for palindrome numbers, and creating a simple login system with limited attempts. Each problem encourages the development of fundamental programming skills through practical exercises.

Uploaded by

mirella363636
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)
9 views2 pages

Python Practice Problems Level 1.5-2

The document outlines a series of custom Python practice problems aimed at levels 1.5 to 2. It includes tasks such as counting digits without converting to string, checking for palindrome numbers, and creating a simple login system with limited attempts. Each problem encourages the development of fundamental programming skills through practical exercises.

Uploaded by

mirella363636
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

Custom Python Practice Problems - Level 1.

5 to 2

1. Count Digits Without Using str()

- Input a number. Without converting it to string, count how many digits it has.

2. Palindrome Number Check

- Check whether the given number is a palindrome. (e.g., 121 is a palindrome)

3. Sum of Even and Odd Digits Separately

- Input a number. Print the sum of its even digits and odd digits separately.

4. Custom Multiplication Table

- Input a number `n`. Print its multiplication table in reverse from 10 to 1.

5. Sum of First n Primes

- Input `n`. Find the sum of the first `n` prime numbers.

6. Check Armstrong Number (3-digit only)

- Example: 153 -> 1^3 + 5^3 + 3^3 = 153

7. Star Pyramid Pattern

Input: 4

Output:

***

*****

*******

8. Find All Factors of a Number

- Input a number and print all its factors (excluding 1 and itself too).

9. Count Vowels and Consonants

- Input a string. Count how many vowels and how many consonants.
10. Simple Login System (3 tries only)

- Predefined username/password. Let user attempt login max 3 times. Lock them out after 3 fails.

Common questions

Powered by AI

To check if a number is a palindrome without converting it to a string, reverse the number using arithmetic operations. Start by initializing a reversed number as 0. Then, repeatedly take the last digit of the input number (using modulus 10), add it to the reversed number after multiplying the reversed number by 10, and remove the last digit of the input by integer division by 10. Compare the original number with the reversed number .

To create a reverse multiplication table for a number, start a loop from 10 to 1, multiplying the given number `n` by each iterating number `i` and print the result in each iteration. This will display the table in reverse order from 10 to 1 .

To find all factors of a number, initialize a loop that iterates through numbers from 2 up to the square root of the number. For each iteration, check if it divides the number evenly. If it does, it is a factor. Collect these in a list and exclude 1 and the number itself .

To count the digits in a number without converting it to a string, repeatedly divide the number by 10 until it becomes 0. With each division, increment a counter to keep track of the number of divisions, which equates to the digit count .

To efficiently sum the first n prime numbers, implement a function to check if a number is prime and use it in an iterative process. Start from number 2 and keep adding each confirmed prime number to the sum until n prime numbers are found and summed .

To find the sum of even and odd digits in a number, initialize two sums for even and odd digits. Then, iterate over each digit of the number (using modulus and division operations), checking if each digit is even or odd and adding it to the respective sum .

A three-digit number is an Armstrong number if the sum of the cubes of its digits equals the number itself. For example, for the number 153, calculate 1^3 + 5^3 + 3^3, which equals 153, confirming it as an Armstrong number .

To count vowels and consonants in a string, iterate through each character, checking whether it is a vowel or consonant using conditions or membership tests in a set of vowels. Increment respective counters for vowels and consonants excluding non-alphabetic characters .

To generate a star pyramid pattern, use a loop to incrementally increase the number of stars printed on each line. For `n` lines, the k-th line will contain `(2*k - 1)` stars, centered by adjusting the spaces .

To implement a simple login system with limited attempts, set predefined username and password credentials. Allow the user to input their credentials up to 3 times, and lock them out after 3 failed attempts without converting attempts into explicit iterations in case structures .

You might also like