Replies: 29 comments 14 replies
|
Answers:
x = 10
y = -20
print(x + y)What this code does is adds 10 + -20, resulting in -10 |
x = ['Hello', 'World']
y = ''
for i in x:
y += i + ' '
print(y)This code will go through each element in the x string list and print out "Hello World" as a result. |
x = input ('Enter your first number')
y= input ('Enter your second number')
print(x+y)What it does: asks the user for two numbers, then adds them together |
x=[2,-4,6,7,-1]
for i in x:
if i<0:
print(i)This code runs a for loop through the list and prints any negative numbers. |
x = float(input("Enter any number (positive or negative)"))
if x<0:
print("This number is negative")
elif x == 0:
print("You found a loophole")
else:
print("This number is positive")This code determines if an inputted number is positive, negative, or zero |
|
Answers name = input("What is your name? ")
print("Hello, " + name + "!")
age = int(input("How old are you? "))
next_year_age = age + 1
print("Next year, you will be", next_year_age, "years old.")This Python code asks the user for their name and age, then prints a greeting using their name. It also adds 1 to their age and tells them how old they will be next year. |
number = 5
print(number * 2)This code creates a variable called number and stores the value 5 then multiplies it by 2 and prints out the answer 10 |
print("Hello World") This is the first piece of Python code I ever learned. It is a very simple program that prints the words "Hello World" to the screen. Even though its basic, it was my introduction to programming and helped me start learning Python. |
|
1.My go to spot this summer will be Glastonbury, primarily because they have amazing restaurants. x and y are variables (they can be letter or numbers), when I include the print (x+y) this combines the two variables together and gives, I love roses because they smell nice and make good decor on my desk |
`age = int(input("Enter age: ")) if age >= 18: |
x = input('Choose a whole number 1-10\n')
y = input('Choose a second whole number 1-10\n')
x1 = int(x)
y1 = int(y)
z = x1 - y1
if z > 0:
print('Your second number is smaller than your first')
elif z < 0:
print('Your second number is larger than your first')
else:
print('Your first and second numbers are the same')This program takes 2 numerical inputs, converts them to integers, and then check which number is larger or if they are equal |
users = " John Perry Sophia"
users_list = users.split()
print(users_list)This code takes an unseperated list of names and seperates them into individual entites. It would display ['John', 'Perry', 'Sophia'] |
print(total_fruit) We create a label called "apples" and "bananas" and assign it the numbers 3 and 2 respectively. Then we tell the computer to add those two labels together and save the result under a new label. Lastly, we ask the computer to show us the final answer, which prints out 5. |
number = 10
for i in range(number):
print('Its-The-Official')``` |
x = 2
y = 3
print(x**y) |
matrix = [
[1, 3, 5],
[2, 4, 6],
[3, 5, 7]
]
print(matrix[1][2], matrix[2][2]) |
My favorite summer spot to be is inside preferably in air conditioning. I find summer to be way to hot and annoying, I prefer the fall season, then I enjoy doing outdoor activities.
I did not come into this course looking to work on any specific skills, I honestly did not know what to expect from this class. Now that I have had a chance to assess the material, I am excited to improve my python skills. I unfortunately do not really get to use programming as a daily skill so what I learn keeps degrading. I am also happy to be using and learning platforms like GitHub.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
sum = num1 + num2
print("The sum is:", sum)This program will take 2 user inputted numbers and add them together. The program can handle numbers with decimals as well. |
name = input('What is your name? ')
age = input('What is your age? ')
mood = input('How are you feeling? ')
person = {
'name' : name,
'age' : age,
'mood' : mood,
}
print(person)This code prompts the user for their name, age, and mood, and then stores the information in a dictionary with the respective keys. It then prints the whole dictionary. |
distance = 120
time = 2
speed = distance / time
print("The speed is", speed, "miles per hour")This code calculates and prints speed. |
speed = float(input("Enter the current speed of the car in mph:"))
acceleration = float(input("Enter the acceleration in mph/s: "))
target_speed =30
time = (target_speed - speed)/acceleration
print("Time to reach 30 mph:",time, "seconds") |
x = input("Enter your number: ")
y = " is my chosen number"
print(x+y)This code asks the user for a number input for the variable x, and sets the y variable to the text " is my chosen number", finally printing the two strings together, giving an example outcome of: "5 is my chosen number." |
name = "Nas"
print("Hello, " + name + "!")This code stores a name in a variable and then prints a greeting. |
will print the text: Hello World |
x = 5
y = 3
print(x + y)This code creates the variables x and y, stores the values 5 and 3 in them, adds them, and prints the result, which is 8. |
|
What's your favorite Summer spot to be?
This code assigns the numerical values of 4 and 8 to the variables mass and volume. It then calculates the density using the formula density = mass / volume and prints the resulting value of 0.5. |
|
Hey everyone, my name is Marshall.
Fahr = float(input("Enter a Fahrenheit value")) Cels = (Fahr - 32) * 5/9 print("Temperature in Celsius", Cels) This code takes a fahrenheit input and converts it into celsius. I think its cool because its the second example of coding used in the C programming language, just translated to python. |
|
Hi my name is Alex!
def square(number): result = square(5) This code defines a function called square that takes a number as input and returns its square. The function is called with the value 5, and the program prints 25. |
|
def is_anagram(word1, word2):
if sorted(word1)==sorted(word2)
return True
else:
return False |
Uh oh!
There was an error while loading. Please reload this page.
Greetings!
I'm excited to get started with our exploration of computational problem solving for engineering problems. We'll use Python to make functions, plots, and analyze data and equations. Its one of my favorite classes and applications.
Let's get started by using the Discussion board. Its a public-facing discussion, so you don't have to use your name in any of these chats. Answer these three questions,
becomes,
All reactions