Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions Armstrong.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
import math
a=int(input("Enter a number to check : "))
temp=a
ans=0
while a!=0:
res = a % 10
ans += math.pow(res,3)
a //=10
if(temp==ans):
print("This number is armmstrong")
else:
print("This is not armstrong")
def is_armstrong_number(num):
"""
Check if a number is an Armstrong number.
An Armstrong number is a number that is equal to the sum of its own digits
each raised to the power of the number of digits.

Args:
num (int): The number to check

Returns:
bool: True if the number is an Armstrong number, False otherwise
"""
if not isinstance(num, int) or num < 0:
return False

# Convert to string to easily get number of digits
num_str = str(num)
num_digits = len(num_str)

# Calculate sum of each digit raised to the power of num_digits
total = sum(int(digit) ** num_digits for digit in num_str)

return total == num


def main():
"""Main function to run the Armstrong number checker."""
try:
# Get input from user with validation
user_input = input("Enter a number to check: ").strip()

# Validate input is a non-negative integer
if not user_input.isdigit():
print("Error: Please enter a valid non-negative integer.")
return

number = int(user_input)

# Check if it's an Armstrong number
if is_armstrong_number(number):
print(f"{number} is an Armstrong number!")
else:
print(f"{number} is not an Armstrong number.")

except KeyboardInterrupt:
print("\nOperation cancelled by user.")
except Exception as e:
print(f"An unexpected error occurred: {e}")


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions Bubble-Game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bubble Number Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="game-container">
<h1>Bubble Number Game</h1>
<div class="game-info">
<div class="target">Target: <span id="target-number">5</span></div>
<div class="score">Score: <span id="score">0</span></div>
<div class="timer">Time: <span id="time">30</span>s</div>
</div>
<div class="game-area" id="game-area">
<!-- Bubbles will be generated here -->
</div>
<div class="controls">
<button id="start-btn">Start Game</button>
<button id="reset-btn" disabled>Reset</button>
</div>
<div class="message" id="message"></div>
</div>
<script src="script.js"></script>
</body>
</html>
111 changes: 111 additions & 0 deletions Bubble-Game/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
document.addEventListener('DOMContentLoaded', () => {
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const gameArea = document.getElementById('game-area');
const targetNumber = document.getElementById('target-number');
const scoreElement = document.getElementById('score');
const timeElement = document.getElementById('time');
const messageElement = document.getElementById('message');

let score = 0;
let timeLeft = 30;
let gameInterval;
let currentTarget;
let gameActive = false;

startBtn.addEventListener('click', startGame);
resetBtn.addEventListener('click', resetGame);

function startGame() {
if (gameActive) return;
gameActive = true;
score = 0;
timeLeft = 30;
scoreElement.textContent = score;
timeElement.textContent = timeLeft;
messageElement.textContent = '';
startBtn.disabled = true;
resetBtn.disabled = false;
generateNewRound();
gameInterval = setInterval(updateTimer, 1000);
}

function resetGame() {
gameActive = false;
clearInterval(gameInterval);
score = 0;
timeLeft = 30;
scoreElement.textContent = score;
timeElement.textContent = timeLeft;
targetNumber.textContent = '5';
messageElement.textContent = '';
startBtn.disabled = false;
resetBtn.disabled = true;
clearBubbles();
}

function updateTimer() {
timeLeft--;
timeElement.textContent = timeLeft;
if (timeLeft <= 0) {
endGame();
}
}

function endGame() {
gameActive = false;
clearInterval(gameInterval);
clearBubbles();
messageElement.textContent = `Game Over! Final Score: ${score}`;
startBtn.disabled = false;
resetBtn.disabled = true;
}

function generateNewRound() {
clearBubbles();
currentTarget = Math.floor(Math.random() * 10) + 1; // 1-10
targetNumber.textContent = currentTarget;
const bubbleCount = 6;
const numbers = [currentTarget];
while (numbers.length < bubbleCount) {
const num = Math.floor(Math.random() * 10) + 1;
if (!numbers.includes(num)) {
numbers.push(num);
}
}
// Shuffle numbers
for (let i = numbers.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[numbers[i], numbers[j]] = [numbers[j], numbers[i]];
}
// Create bubbles
numbers.forEach(num => {
const bubble = document.createElement('div');
bubble.className = 'bubble';
bubble.textContent = num;
bubble.style.left = Math.random() * (gameArea.clientWidth - 60) + 'px';
bubble.style.top = Math.random() * (gameArea.clientHeight - 60) + 'px';
bubble.addEventListener('click', () => handleBubbleClick(num));
gameArea.appendChild(bubble);
});
}

function handleBubbleClick(num) {
if (!gameActive) return;
if (num === currentTarget) {
score++;
scoreElement.textContent = score;
generateNewRound();
} else {
// Wrong bubble, maybe penalize or just continue
messageElement.textContent = 'Wrong! Try again.';
setTimeout(() => messageElement.textContent = '', 1000);
}
}

function clearBubbles() {
while (gameArea.firstChild) {
gameArea.removeChild(gameArea.firstChild);
}
}
});
101 changes: 101 additions & 0 deletions Bubble-Game/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.game-container {
text-align: center;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
}

h1 {
color: #333;
margin-bottom: 20px;
}

.game-info {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
font-size: 18px;
font-weight: bold;
}

.game-area {
position: relative;
width: 100%;
height: 400px;
border: 2px solid #333;
border-radius: 10px;
margin-bottom: 20px;
overflow: hidden;
background-color: #e6f3ff;
}

.bubble {
position: absolute;
width: 60px;
height: 60px;
border-radius: 50%;
background-color: #4CAF50;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s;
animation: float 3s ease-in-out infinite;
}

.bubble:hover {
transform: scale(1.1);
}

@keyframes float {
0%, 100% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
}

.controls {
margin-bottom: 20px;
}

button {
padding: 10px 20px;
font-size: 16px;
margin: 0 10px;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
transition: background-color 0.3s;
}

button:hover {
background-color: #45a049;
}

button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}

.message {
font-size: 18px;
font-weight: bold;
color: #333;
min-height: 24px;
}
Loading