Replies: 14 comments 14 replies
-
Assistant coaching my x2 sons little league Fall baseball team. My youngest son was the youngest player and he did a great job!
def hello_you(name):
out = 'hello ' + name
print(out)
return out
This code create a function called e.g. >>> hello_you('Batman');
hello Batman |
Beta Was this translation helpful? Give feedback.
-
I saw Noah Kahan perform at Fenway over the summer and it was the highlight of my year although it was not necessarily an achievement
number = input("Enter a number:")
if int(number) % 2 == 0:
print("The number", number, "is even")
else:
print("The number", number, "is odd")
This code asks the user to input a number and outputs whether the number is even or odd. It takes the input and uses the % operator to check if there is a remainder after dividing it by 2. If there is no remainder, the number is divisible by 2 and therefore an even number. However, if there is a remainder then the number is odd. These two outputs are done using an if-else statement. |
Beta Was this translation helpful? Give feedback.
-
import random
def Gambling():
DiceFace = random.randint(1, 6)
Gamble = int(input("Guess which side of the dice is up: "))
if Gamble == DiceFace:
print("You Win!!")
else:
print("(╯°□°)╯︵ ┻━┻ Get Outta Here!")
This code randomly selects "a side of a dice" or rather an integer number from 1 to 6, then prompts a user to enter a number, if the user is right they win! If the user is wrong then it prints an emoji of flipping a table over in a comedic/angry way e.g. #call to begin:
Gambling()
Guess which side of the dice is up (1-6): 2
(╯°□°)╯︵ ┻━┻ Get Outta Here! |
Beta Was this translation helpful? Give feedback.
-
I completed the second to last semester of my undergraduate education.
import random
answer = random.randint(1, 10)
guess = int(input("Pick a number 1 through 10: "))
if guess == answer:
print("Good guess!")
else:
print("Incorrect, the correct number was", answer)
This code asks the user to guess a numebr 1-10, It uses the random funciton to randomly choose the correct answer, and if the user guesses correctly, it congratulates them. If they guess incorrectly, it tells them the correct guess. |
Beta Was this translation helpful? Give feedback.
-
import numpy as np
mass = 5
damper = 10
spring_constant = 100
critical_damping = 2 * np.sqrt(spring_constant*mass)
damping_ratio = damper/critical_damping
print(damping_ratio)
|
Beta Was this translation helpful? Give feedback.
-
1.Tell us your biggest achievement in 2024 I'm trying to get my GPA up, before this semester it was below 3.0 but this Fall I got a 3.8 term GPA which brought it to be above a 3.0 GPA 2.Add some Python code that performs a task initial_time = input("Enter the time in 12hr format , just hour:time (Ex: 12:00 or 4:00) : ")
time_of_day = input("Enter the time of day (Ex: AM or PM): ")
initial_hour = int(initial_time.split(":")[0])
initial_mins = int(initial_time.split(":")[1])
if time_of_day == "AM" and 1<=initial_hour<12:
print("Your time in 24 hr time is " + str(initial_hour) + ":" + str(initial_mins))
elif time_of_day == "PM" and initial_hour != 12:
print("Your time in 24 hr time is " + str(int(initial_hour) + 12 ) +":"+ str(initial_mins))
elif time_of_day == "PM" and initial_hour == 12:
print("Your time in 24 hr time is " + str(initial_hour) + ":" + str(initial_mins))
elif time_of_day == "AM" and initial_hour == 12:
print("Your time in 24 hr time is " + "00" +":"+ str(initial_mins)) 3.Tell us what task the code does and how it works or why you wrote it that way The goal of this code is to convert 12 hr time to 24 time format or military time format. If the hour is greater than 12 PM and less than or equal to 11 then you add 12 and if its between 1 AM and 12 PM, the time stays the same, you just the drop AM or PM. In the case of 12 AM, it becomes 00 for the hours. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
2.Add some Python code that performs a task def solve_linear_equation(a, b):
if a == 0:
return "No solution" if b != 0 else "Infinite solutions"
return -b / a
a = 2
b = -4
solution = solve_linear_equation(a, b)
print(f"The solution to the equation {a}x + {b} = 0 is: x = {solution}") 3.Tell us what task the code does and how it works or why you wrote it that way The code solves a linear equation ax+b=0 by checking for special cases (no solution or infinite solutions) and calculating x=−b/a when 𝑎≠0. It’s written this way to handle all scenarios cleanly and efficiently. |
Beta Was this translation helpful? Give feedback.
-
Apart from the many personal issues I have gone through while working and studying throughout the year, achievements that I am proud of is finally learning how to drive a stick shift car, but also becoming a seasonal preschool teacher.
num1 = 6
num2 = 4
sum_result = num1 * num2
print("The product of", num1, "and", num2, "is:", sum_result)
This code finds the product of two predefined numbers and then displays the result. Two numbers, num1 and num2, are defined and their product is calculated by using the * operator. This number is then stored in sum_result, where the result is printed in a readable format when running the code. |
Beta Was this translation helpful? Give feedback.
-
I went hunting for the first time this year and had an amazing meal of pheasant afterword's
import random
# Ask the user to input a number between 1 and 10
user_input = int(input("Enter a number between 1 and 10: "))
# Pick a random number between 1 and 10 and compare it
random_number = random.randint(1, 10)
print("The random number is:", random_number)
#Output statement based on result
if user_input == random_number:
print("Congratulations! You guessed the correct number!")
else:
print("Sorry, the correct number was:", random_number)
This code creates a random number 1 - 10 and asks a user to predict the number. It will then inform the user if the guess was correct or incorrect based on the input and random number values. |
Beta Was this translation helpful? Give feedback.
-
This fall, I successfully completed five classes while commuting 55 minutes to school Monday through Friday and working a full-time night job.
def add_two_ numbers(a, b):
return a + b
result = add_two_numbers (5, 3)
print ( f"the sum of 5 and 3 is {result}")
this code create a function , add_two_numbers, that take 2 numbers a and b as input and returns their sum. the result from the function is stored in the variable result, which is then printed. e.g. >>> add_two_numbers(a, b):
the sum of 5 and 3 is 8 |
Beta Was this translation helpful? Give feedback.
-
age=int(input("Please enter your age: "))
if age>=18:
print("You are an adult")
else:
print("You are still young")
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
numbers = [1, 2, 3, 4, 5]
squared = [x**2 for x in numbers]
print(f"Original: {numbers}")
print(f"Squared: {squared}")
|
Beta Was this translation helpful? Give feedback.
-
Greetings,
This is your go-to discussion forum for ME3255 - Computational Mechanics. We are going to fly through this course
These discussion posts are public, so if there are any personal topics you want to discuss email/appointment is better.
Try out some of the awesome features that can help us connect and learn Python+Computational Mechanics together,
hint: use the
```python ```
backticks to make formatted Python codeBeta Was this translation helpful? Give feedback.
All reactions