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
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 ….
Last changed6 days ago