Practice PHP Coding Problems
Improve your skills by solving real PHP coding problems.
Write code, submit, and get instant feedback.
Weekly Problem
Double or Nothing
Double a number if it is positive, otherwise print zero.
main.py
n = int(input())
# Double if positive, otherwise print 0
Free Practice Problems
More Practice Problems
Sign in to unlock all Practice Problems.
| Problem | Description | Difficulty | XP | |
|---|---|---|---|---|
| Shopping Receipt | Read item details from input and print a short receipt. | Easy | 20 XP | |
| Personal Info | Read personal details from input and display them. | Easy | 20 XP | |
| Swap Values | Read two values and print them in swapped order. | Easy | 20 XP | |
| Rectangle Border | Print a rectangle border made of stars. | Easy | 20 XP | |
| Repeat Message | Read a message and a number, then print the message that many times. | Easy | 20 XP | |
| Currency Exchange | Calculate a currency exchange from an amount and rate. | Easy | 20 XP | |
| BMI Calculator | Calculate Body Mass Index from weight and height. | Easy | 20 XP | |
| Circle Properties | Calculate the circumference and area of a circle. | Easy | 20 XP | |
| Simple Calculator | Perform basic arithmetic on two numbers. | Easy | 20 XP | |
| Discount Price | Calculate a discounted price from a price and discount percentage. | Easy | 20 XP | |
| Split the Bill | Split a total amount equally among a group of people. | Easy | 20 XP | |
| Digit Extractor | Extract the individual digits of a 3-digit number. | Easy | 20 XP | |
| Word Counter | Count the number of words in a sentence. | Easy | 20 XP | |
| Shout It Out | Convert a string to uppercase and print its length. | Easy | 20 XP | |
| First and Last | Print the first and last character of a word. | Easy | 20 XP | |
| Repeat String | Read a string and a number, then print the string repeated that many times. | Easy | 20 XP | |
| Range Checker | Check if a number falls within a given range. | Easy | 20 XP | |
| Password Check | Check if a password is long enough. | Easy | 20 XP | |
| Ticket Price | Determine the ticket type and price based on age. | Easy | 20 XP | |
| Positive Negative Zero | Check if a number is positive, negative, or zero. | Easy | 20 XP | |
| Smallest of Three | Find the smallest of three numbers. | Easy | 20 XP | |
| Countdown | Count down from a number to 1 and print Go! | Easy | 20 XP | |
| FizzBuzz | Implement the classic FizzBuzz challenge. | Easy | 20 XP | |
| Sum 1 to N | Calculate the sum of all numbers from 1 to N. | Easy | 20 XP | |
| Star Triangle | Print a right triangle made of stars. | Easy | 20 XP | |
| Tip Calculator | Create a tip calculator function for a restaurant bill. | Easy | 20 XP | |
| Power Function | Write a function that calculates the power of a number. | Easy | 20 XP | |
| Average Score | Read a list of scores and calculate their average. | Easy | 20 XP | |
| Count Matches | Count how many numbers in a list match a target value. | Easy | 20 XP | |
| Min and Max | Find the smallest and largest numbers in a list. | Easy | 20 XP | |
| Absolute Difference | Calculate the absolute difference between two numbers. | Easy | 20 XP | |
| Round Up or Down | Round a decimal number to the nearest whole number. | Easy | 20 XP | |
| Double or Nothing | Double a number if it is positive, otherwise print zero. | Easy | 20 XP | |
| Leap Year | Determine if a given year is a leap year. | Medium | 50 XP | |
| Day of Week | Convert a day number to a day name. | Medium | 50 XP | |
| Triangle Classifier | Classify a triangle based on its side lengths. | Medium | 50 XP | |
| Time Converter | Convert a number of seconds into hours, minutes, and seconds. | Medium | 50 XP | |
| Reverse Words | Reverse the order of words in a sentence. | Medium | 50 XP | |
| Palindrome Check | Check if a word reads the same forwards and backwards. | Medium | 50 XP | |
| Count Vowels | Count the number of vowels in a string. | Medium | 50 XP | |
| Title Case | Capitalize the first letter of each word in a sentence. | Medium | 50 XP | |
| Remove Duplicates | Remove consecutive duplicate characters from a string. | Medium | 50 XP | |
| Longest Word | Find the longest word in a sentence. | Medium | 50 XP | |
| Access Control | Determine if a person gets access based on role, age, and membership. | Medium | 50 XP | |
| Digit Sum | Calculate the sum of all digits in a number. | Medium | 50 XP | |
| Number Pyramid | Print a pyramid of numbers. | Medium | 50 XP | |
| Collatz Steps | Count the steps to reach 1 using the Collatz sequence. | Medium | 50 XP | |
| Prime Check | Check if a number is a prime number. | Medium | 50 XP | |
| Reverse Number | Reverse the digits of a number. | Medium | 50 XP | |
| Is Palindrome Function | Write a function that checks if a word is a palindrome. | Medium | 50 XP | |
| Min of Three | Write a function that returns the smallest of three numbers. | Medium | 50 XP | |
| Count Digits | Write a function that counts the number of digits in a number. | Medium | 50 XP | |
| Recursive Sum | Write a recursive function to sum numbers from 1 to N. | Medium | 50 XP | |
| Array Map Function | Write a function that doubles every number in a list. | Medium | 50 XP | |
| Find the Largest | Read a list of numbers and find the largest one. | Medium | 50 XP | |
| Reverse a List | Read a list of numbers and print them in reverse order. | Medium | 50 XP | |
| Second Largest | Find the second largest number in a list. | Medium | 50 XP | |
| Running Sum | Print the running (cumulative) sum of a list of numbers. | Medium | 50 XP | |
| Count Above Average | Count how many numbers are above the average. | Medium | 50 XP | |
| Longest Streak | Find the longest consecutive streak of the same number. | Medium | 50 XP | |
| Greatest Common Divisor | Find the greatest common divisor (GCD) of two numbers. | Medium | 50 XP | |
| Fibonacci | Print the first N numbers of the Fibonacci sequence. | Medium | 50 XP | |
| Prime Factors | Find all prime factors of a number. | Medium | 50 XP | |
| Power of Two | Check if a number is a power of 2. | Medium | 50 XP | |
| Sum of Squares | Calculate the sum of squares from 1 to N. | Medium | 50 XP | |
| LCM Calculator | Calculate the least common multiple of two numbers. | Medium | 50 XP | |
| Perfect Number | Check if a number is a perfect number. | Medium | 50 XP | |
| Sort Three Numbers | Read three numbers and print them in ascending order. | Medium | 50 XP | |
| Sort Numbers | Read a list of numbers and print them sorted. | Medium | 50 XP | |
| Sort Words | Read a list of words and print them sorted alphabetically. | Medium | 50 XP | |
| Letter Frequency | Count how many times each letter appears in a word. | Medium | 50 XP | |
| Most Common Char | Find the character that appears most often in a string. | Medium | 50 XP | |
| Digit Frequency | Count how many times each digit appears in a number. | Medium | 50 XP | |
| Caesar Cipher | Encrypt a message by shifting each letter in the alphabet. | Hard | 100 XP | |
| Anagram Check | Check if two words are anagrams of each other. | Hard | 100 XP | |
| Run Length Encoding | Compress a string using run-length encoding. | Hard | 100 XP | |
| Date Validator | Check if a given date is valid. | Hard | 100 XP | |
| Diamond Pattern | Print a diamond pattern of stars. | Hard | 100 XP | |
| Number to Binary | Convert a decimal number to binary. | Hard | 100 XP | |
| Pascal Triangle Row | Print a specific row of Pascal's triangle. | Hard | 100 XP | |
| Remove Duplicates | Remove duplicate numbers from a list while keeping order. | Hard | 100 XP | |
| Rotate Left | Rotate a list of numbers to the left by K positions. | Hard | 100 XP | |
| Merge Sorted | Merge two sorted lists into one sorted list. | Hard | 100 XP | |
| Pair Sum | Find the first pair of numbers that add up to a target. | Hard | 100 XP | |
| GCD Function | Write a recursive function to find the GCD of two numbers. | Hard | 100 XP | |
| Number Base Convert | Convert a number from one base to another. | Hard | 100 XP | |
| Bubble Sort | Implement bubble sort and count the number of swaps. | Hard | 100 XP | |
| Selection Sort | Implement selection sort and print each step. | Hard | 100 XP | |
| Insertion Sort | Implement insertion sort and print each step. | Hard | 100 XP | |
| Word Frequency | Count how many times each word appears in a sentence. | Hard | 100 XP | |
| Unique Elements Count | Count how many unique numbers appear in a list. | Hard | 100 XP |
How it Works
Each challenge gives you starter code in PHP. Your program reads input and prints the correct output.
When you submit, your code is tested against multiple hidden test cases with different inputs.
Your score is based on how many tests pass — partial credit is given for partially correct solutions.