make this a coment
print("Welcome to the YouTube Channel Name Generator: ")
#print("Welcome to the YouTube Channel Name Generator: ")
What is the output in python language?
Round (.4)-Round (-.5)
Remember this
round(.4) = 0
round(.4)
round(-.5) = -0 (which is the same as 0)
round(-.5)
Therefore, round(.4) - round(-.5) = 0 - 0 = 0
round(.4) - round(-.5)
Here are some examples to help you understand:
Positive Numbers:
round(3.4) = 3 (because 3.4 is closer to 3)
round(3.4)
round(3.6) = 4 (because 3.6 is closer to 4)
round(3.6)
round(3.5) = 4 (special case - rounds to the nearest even number)
round(3.5)
Negative Numbers:
round(-3.4) = -3
round(-3.4)
round(-3.6) = -4
round(-3.6)
round(-3.5) = -4 (again, rounds to the nearest even number)
round(-3.5)
If the decimal part is less than .5, it rounds down
If the decimal part is .5 or greater, it rounds up
For .5 exactly, it rounds to the nearest even number
make this output
What is your name?
Eyad(what the user will write for example)
Hello Eyad
print ("Hello" + input ("What is your name? \n"))
EX
print ("Hello" + "Eyad")
why there is an error here
print (len (123455) )
There's an error in this code because len() is a function used to determine the length of sequences like strings, lists, or tuples, but it cannot be directly used with an integer.
len()
When you try to use len() with an integer like 123455, Python raises a TypeError. This is because len() expects an object that has a length (such as a string, list, tuple, dictionary, etc.), but an integer does not have a length.
123455
If you want to find the number of digits in an integer, you can convert it to a string first:
print(len(str(123456))) # This will print 6
=
print (len ("123456"))
THE TRUE ONE
len(“octucode“)
the output will be
8
What will be the output of this
print (type (3))
print (type ("3"))
print (type (True))
<class 'int'>
<class 'str'>
<class 'bool’>
Correct the following code
print ("eyad"+ 5 )
print ("eyad"+ str(5) )
OR
print (f"eyad {5}" )
f = formatted: It refers to embedding values or expressions directly within the string
f
print ("eyad" , 5 )
Example
print(f"eyad {5}") #Output: eyad 5
eyad 5
print(f"eyad{5}") #Output: eyad5
eyad5
Explnation
print() itself is flexible. The key is how you combine different types of data. The error occurs when you try to use the + operator to combine incompatible types.
print()
+
What is the output
for x in range(1,6):
print (x, "squared is", x * x)
for x in range(5, 0, -1):
print (x)
print ( "eyad")
for x in range(5, 0, -1): #range(start, stop, step)
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
5 squared is 25
5
eyad
4
3
2
1
1. What is the output of the below program in python:
print(0.2+0.4==0.6)
A. True
B. False
C. Error
D. Depends on machine
See this after answering
Answer: B: False due to not compare floating point value
print(0.2 + 0.4) # Output: 0.6000000000000001
print(0.2 + 0.4 == 0.6) # Output: False
what is mean of case-sensitive language?
what is mean Interpreted language?
what is mean Portable?
meaning that variable names, function names, and keywords must be written with the exact same capitalization. For example, print and Print are considered two different identifiers in Python.
print
Print
is an interpreted language, as code is executed line by line.
code can run on different platforms (e.g., Windows, macOS, Linux) without modification.
Developer of Python programming?
Guido van Rossum
What is output for below code?
a=2
b=3
print(a,b)
a,b=b,a
2 3
3 2
Let’s break this down step by step:
a = 2 b = 3 print(a, b) a, b = b, a print(a, b)
a = 2
b = 3
The first print(a, b) will display:
print(a, b)
The line a, b = b, a swaps the values of a and b:
a, b = b, a
a
b
The right-hand side of the assignment evaluates first:
b, a becomes 3, 2.
b, a
3, 2
Then, these values are assigned to a and b respectively:
a gets the value 3.
b gets the value 2.
The second print(a, b) will display:
The line a, b = b, a uses tuple unpacking to swap values in a single step. This is a concise and Pythonic way to exchange the values of two variables without needing a temporary variable.
what will be the output of these code
fruits = ["apple", "orange", "banana", "coconut"]
print(fruits[2])
for x in fruits:
print(x)
#——————————
for y in "fruits":
print(y)
print("pinaple" in fruits)
fruits.append("pineapple")
fruits.remove ("apple")
print(fruits)
fruits.insert(0, "pineapple")
# Inserting "pineapple" at index 0
fruits.sort()
fruits.reverse()
fruits.clear()
fruits = ["apple", "apple", "banana", "coconut"]
print (fruits.count("apple"))
print (dir(fruits))
banana
apple
orange
coconut
r
u
i
t
s
False
you can use the in operator to find if a value is within a list
['orange', 'banana', 'coconut', 'pineapple']
to add an element to the end of a list use the append method
to remove an element you can use the remove method
['pineapple', 'apple', 'orange', 'banana', 'coconut']
['apple', 'banana', 'coconut', 'orange']
the sort method will sort a list fruits.sort
these are all in alphabetical order now apple banana coconut orange
['coconut', 'banana', 'orange', 'apple']
[]
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Write a program that asks the user to input an area from the following list:
Cairo
Alexandria
Tanta
Based on the user's input:
If they choose Cairo (case insensitive), display: "You chose Cairo"
"You chose Cairo"
If they choose TANTA (specifically in uppercase), display: "TANTA is nice!"
"TANTA is nice!"
If they choose Alexandria (case insensitive), display: "Feels like summer!"
"Feels like summer!"
If the user's input does not match any of the above options, display: "Sorry, [input] is not on our list!" (Replace [input] with whatever the user typed.)
"Sorry, [input] is not on our list!"
[input]
Make sure to handle different cases of user input (like uppercase and lowercase letters) EX CaIRO = cario.
area = input("Chose an area: (Cairo), (Alexandria), or (Tanta)")
if area.lower() == "cairo": print ("You chose Cairo")
if
area.lower
() == "cairo": print ("You chose Cairo")
elif area.upper() == "TANTA": print ("TANTA is nice!")
elif
area.upper
() == "TANTA": print ("TANTA is nice!")
elif area.lower() == "alexandria": print("Feels like summer!")
() == "alexandria": print("Feels like summer!")
else:
print(f"Sorry, {area} is not on our list!")
Correct the follwing code
print ("Welcome to my application")
age = int(input("How old are you? \n"))
if age >= 12:
print("Good. You can use the app")
print ("Sorry, you can't use the app")
Remember this application on if
number = float (input ("Enter a number \n"))
if number > 0:
print ("The number is positive")
elif number == 0:
print ("The number is zero")
elif number < 0:
print ("The number is negative")
this is instead of curly brackets
علشان تحدد البدايه والنهايه بتاعه الكود
if area.lower() == "cairo":
print("You chose Cairo")
elif area.upper() == "TANTA":
print("TANTA is nice!")
elif area.lower() == "alexandria":
print("Feels like summer!")
print("Sorry " + area + "is not on our list!")
area = input("Choose an area: (Cairo), (Alexandria), or (Tanta) ")
if area.lower() == "cairo" or area.lower() == "alexandria" or area.lower() == "tanta":
print(area + " is on our list!")
print("Sorry " + area + " is not on our list!")
Note
we used the upper or lower be. may the user enter the country some small and some capital like this:cAiRo or CAIRO
Python Dictionary is used to store the data in ….
def square(q):
return q * q # Takes a number q and returns q multiplied by itself
X = int(input("Enter a number: ")) # Convert input to an integer
print(square(X))
int
input ("Enter a number: “)
The answer
When you use input() in Python, it always gives you back what the user typed as a string (text), even if they typed numbers. This is because computers can't automatically know if "123" is meant to be the text "123" or the number 123.
Square = lambda q: q * 2
print(Square(2))
The line r = lambda q: q * 2 creates a small function that we're storing in the variable r. Let's break down each part:
r = lambda q: q * 2
lambda is a special keyword that tells Python "I'm creating a quick, simple function"
q is the parameter name (like a variable that will hold whatever input we give the function)
The colon : separates the parameter from what the function will do
q * 2 is the operation - it takes whatever value is in q and multiplies it by 2
What is the output of following program?
a = 4.5
print (a//b)
4.5 / 3 # Regular division: gives us 1.5
4.5 // 3 # Floor division: gives us 1
5.5 // 3 # Floor division: gives us 1
6.0 // 3 # Floor division: gives us 2
a = True
b = False
c = False
if a or b and c:
print ("CAREERBODHSANSTHAN")
print ("careerbodh")
CAREERBODHSANSTHAN
The condition a or b and c is evaluated with the following precedence rules:
1. and has higher precedence than or, so b and c is evaluated first.
b and c is False and False, which results in False.
2. Now, the condition becomes a or False, which is True or False.
3. Since a is True, the entire condition evaluates to True.
Therefore, the if block is executed, printing "CAREERBODHSANSTHAN".
What will be the output of this code
string = "eYAd COURSES"
new_string = string.capitalize()
print(new_string)
Eyad courses
What capitalize() does:
capitalize()
It only changes the first character of the string to uppercase (if it’s a letter).
It converts all other characters in the string to lowercase.
# Initial list
lst = [10, 20, 30, 40, 50]
# Removing the first element using pop(0)
lst.pop(0)
print("After removing first element:", lst)
# Removing the last element using pop()
lst.pop()
print("After removing last element:", lst)
After removing first element: [20, 30, 40, 50]
After removing last element: [20, 30, 40]
What does mutable mean and which two types of python's core types are Considered mutable?
In programming, mutable means that an object can be changed after it is created. In Python, the two core types that are considered mutable are lists and dictionaries.
Write a python code get all prime numbers from 1 to 1000
def is_prime(n):
# If number is less than 2, it's not prime
if n < 2:
return False
# Check if number is divisible by anything up to its square root
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return True
# Create an empty list to store prime numbers
prime_numbers = []
# Loop through numbers 1 to 1000
for num in range(1, 1001):
# If the number is prime, add it to our list
if is_prime(num):
prime_numbers.append(num)
# Print the list of prime numbers
print(prime_numbers)
Zuletzt geändertvor 19 Stunden