Python 3.5.2 .format() [closed] - python-3.x

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I just started to learn python and I cant figure out how to use .format, I get a syntax problem every time I try it. Here's the code.
my_name = input("What is your name:")
my_age = input("What is your age:")
print ("So you are {name} and you are{age}")format(name=my_name,age=my_age)
Can someone tell me what I did wrong?

format is a method of str so you should call that from your string, then pass the result of that into print.
print ("So you are {name} and you are{age}".format(name=my_name,age=my_age))

Related

Can I input a number in scientific notation? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I want to input a large number by scientific notation, for example of distance to sun.
distance = float(input("distance to sun?:"))
I tried to enter 1.471*10**11 and 1.471e11, but both said "could not convert string to float"
Do I have to type the multiple "0"? Thanks for answering in advance.

Im trying to figure out why my squars wont fill with the color black when using turtle library [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Im trying to fill some squars with the color black, but it wont fill
my code:
from turtle import *
setup(1920,1080,0,0)
k=Turtle()
k.right(45)
størrelse=40
n=int(input("Hvor mange diamanter? "))
for i in range(n+1):
color("black")
if i!=0:
if i%2!=0:
begin_fill()
for c in range(4):
k.forward(i*størrelse)
k.right(90)
end_fill()
else:
for c in range(4):
k.forward(i*størrelse)
k.right(90)
k.penup()
k.left(90)
k.forward(størrelse/2)
k.left(90)
k.forward(størrelse/2)
k.left(180)
k.pendown()
done()
If i use this code i only get squars, but they are not filled any solutions?
forgot "k." infront of fill and end function

TypeError: 'str' object is not callable (When printing an integer and words) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
#stage 2 dice rolling
#P1D1 means player ones dice one value and so on with P1D2
import random
print("player ones turn")
P1D1 = random.randint (1,6)
print ("your number is "(P1D1))
(this is in python 3.6.3)
when i run this piece of code it returns str object not callable
but when i run
print(P1D1) it seems to print the number without issue
anyone able to help thanks in advance
The error is caused by your syntax on the last line. By putting the brackets right after a string it is like trying to call the string as a function, just like how putting brackets around print, it calls it. Try this.
print ("your number is ", P1D1)

What is "neg_mean_absolute_error" and where can I find it? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am new to machine learning. I am trying to learn feature selection from this link. Here they have a line of code which is given below
search = GridSearchCV(pipeline, grid, scoring='neg_mean_squared_error', n_jobs=-1, cv=cv)
But whenever I try to run this code I get the error
I cannot find where to import neg_mean_squared_error from. I am not sure where I should write the function myself or not. The tutorial isn't clear on this issue.
It is just a typo.
You need
neg_mean_absolute_error
You typed
neg_mean_absolure_error
using an r instead of t
Reference: https://scikit-learn.org/stable/modules/model_evaluation.html

Converting an int to String in Python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
my_url = "https://swgoh.gg/db/missions/lightside/?stage=M0{}"
for i in range(1,10):
my_url = my_url.format(i)
print(my_url)
print(i)
The variable i increments properly, but my_url always end ins stage=M01. Any help on fixing this to increment with i?
It is required to update my_url as in your case, in 2nd iteration format() looks for {} inside new string and doesn't get it that's why it prints the same string obtained in the first iteration.
Please change your code like this.
for i in range(1,10):
my_url = "https://swgoh.gg/db/missions/lightside/?stage=M0{}".format(i)
print(my_url)
print(i)

Resources