staycia930
staycia930
MModular
Created by staycia930 on 11/26/2024 in #questions
Using the input function will cause Mojo to crash.
Using the input function in the main function causes mojo to crash. Please tell me why it crashes and how to work around it.
fn main():'''
name = input("Enter your name: ”)
print(“Hello”, name)
fn main():'''
name = input("Enter your name: ”)
print(“Hello”, name)
This is the mojoproject.toml
[project].
authors = [“Staycia”].
channels = [“conda-forge”, “https://conda.modular.com/max”]
description = “Add a short description here”
name = “c2024Exam”
platforms = [“osx-arm64”].
version = “0.1.0”

[tasks]

[dependencies]]
max = “>=24.5.0,<25”
[project].
authors = [“Staycia”].
channels = [“conda-forge”, “https://conda.modular.com/max”]
description = “Add a short description here”
name = “c2024Exam”
platforms = [“osx-arm64”].
version = “0.1.0”

[tasks]

[dependencies]]
max = “>=24.5.0,<25”
5 replies
MModular
Created by staycia930 on 7/2/2024 in #questions
I do not know why the output is like this!
I ran two almost identical programmes but the output changed. But I don't understand why the output changes. I would like to know. First Program
def greet(name: String):
name = "Hello, " + name + "!"
print(name)

fn main():
var name = "Mojo"
try:
greet(name)
except e:
print("Error: " , e)
def greet(name: String):
name = "Hello, " + name + "!"
print(name)

fn main():
var name = "Mojo"
try:
greet(name)
except e:
print("Error: " , e)
First output
Hello, Mojo!
Hello, Mojo!
Seccond Program
def greet(name):
name = "Hello, " + name + "!"
print(name)

fn main():
var name = "Mojo"
try:
greet(name)
except e:
print("Error: " , e)
def greet(name):
name = "Hello, " + name + "!"
print(name)

fn main():
var name = "Mojo"
try:
greet(name)
except e:
print("Error: " , e)
Seccond output
'Hello, Mojo!
'Hello, Mojo!
Using my environment ・MacOS ・Python3.12 ・Poetry ・mojo 24.4.0 (2cb57382)
3 replies