Leetcode with dani – Telegram
Leetcode with dani
1.31K subscribers
197 photos
14 videos
56 files
240 links
Join us and let's tackle leet code questions together: improve your problem-solving skills
Preparing for coding interviews
learning new algorithms and data structures
connect with other coding enthusiasts
Download Telegram
#day_note .what is the use of continue statement in python?
,the continue statement is used to skip the rest of the code inside a loop and move on to the next iteration. When the continue statement is encountered, it immediately jumps to the next iteration of the loop without executing any further statements below it in the current iteration

for num in range(1, 6):
if num == 3:
continue
print(num)


Output:

1
2
4
5


In this example, the loop iterates over numbers from 1 to 5. However, when num equals 3, the continue statement is triggered, causing the program to skip printing that particular number and proceed to the next iteration.

The continue statement is commonly used when you want to skip certain iterations based on specific conditions or when you want to exclude certain elements from the loop's processing.
👍4
3. #day_note the upper, lower, and noscript methods in Python.

1. Upper Method:
The upper() method is used to convert all characters in a string to uppercase. It returns a new string with all uppercase letters. Here's an example:

python
string = "hello world"
uppercase_string = string.upper()
print(uppercase_string)  # Output: "HELLO WORLD"
2. Lower Method:
The lower() method is the opposite of upper(). It converts all characters in a string to lowercase. Here's an example:

python
string = "Hello World"
lowercase_string = string.lower()
print(lowercase_string)  # Output: "hello world"



3. Title Method:
The noscript() method is used to capitalize the first letter of each word in a string. It converts the first character of each word to uppercase and all other characters to lowercase. Here's an example:

python
string = "hello world"
noscript_string = string.noscript()
print(noscript_string)  # Output: "Hello World"
👍7
password = input("Enter your password: ")
correct_password = "dani1234"
if password.lower() == correct_password: print("Congratulations.") else: print("Try again.") What is the out put of the above code if the user gives "DAni1234" as input?
Anonymous Quiz
45%
Congratulations.
55%
Try again.
👍6
Leetcode with dani pinned «please make sure to read and understand the lecture I provided above. before answer the question»
4 #day_note
1. Sorting a List using the sorted() Function:
- The sorted() function returns a new sorted list without modifying the original list.
- Syntax: sortedlist = sorted(originallist)
- Example: numbers = 5, 2, 8, 1, 9
sortednumbers = sorted(numbers)
print(sorted
numbers) # Output: 1, 2, 5, 8, 9

2. Sorting a List in-place using the sort() Method:
- The sort() method sorts the list in-place, modifying the original list.
- Syntax: originallist.sort()
- Example: numbers = [5, 2, 8, 1, 9]
numbers.sort()
print(numbers) # Output: [1, 2, 5, 8, 9]

3. Sorting a List in Descending Order:
- Both the sorted() function and the sort() method can sort a list in descending order.
- Syntax: sorted
list = sorted(originallist, reverse=True)
original
list.sort(reverse=True)
- Example: numbers = 5, 2, 8, 1, 9
sortednumbers = sorted(numbers, reverse=True)
print(sorted
numbers) # Output: 9, 8, 5, 2, 1
numbers.sort(reverse=True)
print(numbers) # Output: 9, 8, 5, 2, 1
👍5
numbers =[ 3, 1, 5, 2, 4]
sortednumbers = sorted(numbers)
print(sortednumbers)
Anonymous Quiz
91%
[1,2,3,4,5]
9%
[3,1,5,2,4]
🌚2
3. What will be the output of the following code?
numbers = [3, 1, 5, 2, 4]
numbers.sort(reverse=True) print(numbers)
Anonymous Quiz
14%
[1,2,3,4,5]
11%
[3,1,5,2,4]
75%
[5,4,3,2,1]
👍2
4. What will be the output of the following code?
x = 5
y = 5 print(x != y)
Anonymous Quiz
91%
False
9%
True
👍31
#code_challenge
1. Make a list of five or more usernames, including the name

'admin'. Imagine you are writing code that will print a greeting to each user after they log in to a website. Loop through the list, and print a greeting to each user:

If the username is 'admin', print a special greeting, such as Hello admin, would you like to see a status report?

Otherwise, print a generic greeting, such as Hello john, thank you for logging in again.

.
#code_challenge
Write a program that checks if a given number is even or odd.
#code_challenge write a code that checks if a given input is a palindrome or not.

A palindrome is a word, phrase, number, or sequence of characters that reads the same forwards and backwards. For example, words like "level," "radar," and "madam" are palindromes because they are spelled the same way in reverse.
👍7
#code_challenge Write a program that generates a random number between 1 and 100 and allows the user to guess the number. The program should provide hints (higher or lower) until the user guesses correctly.
# code challenge
Create a program that calculates the factorial of a given number using a for loop
👍61
for answering all of the question you can leave a comment and share the channel for your friends
2❤‍🔥1
which concept is not clear for you until know
🆒1
Here's an explanation of tuples, dictionaries, and sets in Python:

1. Tuples:
A tuple is an ordered, immutable collection of elements enclosed in parentheses (). Tuples are similar to lists, but the main difference is that tuples cannot be modified once created. They are commonly used to store related pieces of data together.

Example:
my_tuple = (1, 2, 3, "hello", True)


2. Dictionaries:
A dictionary is an unordered collection of key-value pairs enclosed in curly braces {}. Each key-value pair is separated by a colon (:), and the keys must be unique. Dictionaries are useful for storing and retrieving data based on a specific key.

Example:
my_dict = {"name": "John", "age": 25, "city": "New York"}


3. Sets:
A set is an unordered collection of unique elements enclosed in curly braces {}. Sets are useful when you want to store a collection of items without any duplicates. They also support mathematical set operations like union, intersection, and difference.

Example:
my_set = {1, 2, 3, 4, 5}


In addition to the basic operations, Python provides various built-in functions and methods to manipulate and work with tuples, dictionaries, and sets. It's important to note that dictionaries and sets are mutable, meaning you can modify their contents after creation, while tuples are immutable and cannot be changed once created.

I hope this explanation helps! Let me know if you have any further questions.
4👍41
Leetcode with dani pinned «Here's an explanation of tuples, dictionaries, and sets in Python: 1. Tuples: A tuple is an ordered, immutable collection of elements enclosed in parentheses (). Tuples are similar to lists, but the main difference is that tuples cannot be modified once created.…»
because of the next question
I'll explain both the while loop and the for loop in Python with examples.

1. While Loop:
A while loop repeatedly executes a block of code as long as a specified condition is true. It continues to execute the code until the condition becomes false. The general syntax of a while loop is as follows:

while condition:
    # code to be executed


Example:
count = 0
while count < 5:
    print("Count:", count)
    count += 1

In this example, the while loop will execute the code block as long as the condition count < 5 is true. It will print the value of count and increment it by 1 in each iteration. The loop will stop when count becomes 5.

Output:
Count: 0
Count: 1
Count: 2
Count: 3
Count: 4


2. For Loop:
A for loop is used to iterate over a sequence (such as a list, tuple, string, or range) or any other iterable object. It executes a block of code for each item in the sequence. The general syntax of a for loop is as follows:

for item in sequence:
    # code to be executed


Example 1:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

In this example, the for loop iterates over each item in the fruits list. It assigns each item to the variable fruit and then executes the code block, which simply prints the value of fruit.

Output:
apple
banana
cherry


Example 2:
for i in range(5):
    print(i)

In this example, the for loop uses the range() function to generate a sequence of numbers from 0 to 4. It assigns each number to the variable i and then executes the code block, which prints the value of i.

Output:
0
1
2
3
4


Both while loops and for loops are powerful tools for automating repetitive tasks and iterating over sequences. The choice between them depends on the specific requirements of your program.
👍5😎1
What is module?
2