What happens if you put a period at the end of a statement in python?

I don't know why but I've just never found a way around this problem.

Nội dung chính

  • Answer 523ebd5980ff33a58c005cf0
  • Answer 52405bbaf10c60fda4003288
  • Answer 52da6abc548c3552d5001cfe
  • Answer 52e852908c1ccc5be6000891
  • Answer 52fa86b3631fe9c70d003c8d
  • Answer 52627374548c35b37d002b86
  • Answer 52cbff8980ff33dee3007d14
  • What happens if you put a period at the end of a statement in Python?
  • What does a period mean in Python?
  • How do you add a period to the end of a sentence in Python?
  • How do you print a period at the end of a Python?

My teacher wanted to get our class involved with coding and asked me to create a basic calculator in python. So I quickly typed up:

num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))

def add(x, y):
    return x + y

print (num1, "+", num2, "is equal to", add(num1, num2))

Simple stuff, I'll add subtraction and all that.

However, being the grammar nazi I am, I cannot find a way to place a period at the end of that print command.

I've solved it before. My first calculator didn't define functions, it just took the integers, then added them together and assigned them a variable and then printed them. I added periods by using %s and putting the variable at the end of the print command.

Also, while if I try to print the option selected in a tkinter window for example with variable.get() I can't seem to put a period at the end either. The only thing I found only was putting + "." at the end or something along those lines.

Can anyone help me?

This is what I have written so far:

length = len(input("What is your name?\n"))

print("The length of your name is ",length,".")

Now, this is my output:

    What is your name?
    Shary
    The length of your name is  5 .

I would like my output to be like the following: "The length of your name is 5."

As you can imagine, by placing a comma next to the Integer length, I have an extra space I would like to take care of. I am new to Python so I do not really know how to solve this.

Any help would be greatly appreciated.

0 points

about 9 years

So after pulling my hair out for 30 mins trying to figure out why Codecademy wouldnt accept my code even though it seemed to give the right answer, i noticed something… you need a period at the end of the printed sentence for the interpreter to pass you.

This is my work and passing, correct code for anyone looking for it.

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg))

my_car = Car("DeLorean", "silver", 88)
print my_car.display_car()

I hope this helps someone that might be frustrated for the same reason as me, because of something simple like a period at the end of that sentence.

Answer 523ebd5980ff33a58c005cf0

hmm, sometimes the judge program is just stupid. I made the same mistake and I just skip it.

points

about 9 years

Answer 52405bbaf10c60fda4003288

Bin there, done that. Only difference was about an hour of further trying. However I think you also learn as you try all the possible other things that might be the problem!

points

about 9 years

Answer 52da6abc548c3552d5001cfe

been trying for long time so thanks a lot :)

points

over 8 years

Answer 52e852908c1ccc5be6000891

What’s up with my code? What am I missing?

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg))

my_car = Car("DeLorean", "silver", 88)
print my_car.dislplay_car()

Traceback (most recent call last):
File “python”, line 11, in

points

over 8 years

Answer 52fa86b3631fe9c70d003c8d

QUESTION: Why don’t you replace %s with %d for mpg? It’s already made for decimals.

return 'This is a %s %s with %d MPG.' % (self.color, self.model, self.mpg)

result: This is a silver DeLorean with 88 MPG.

points

over 8 years

Answer 52627374548c35b37d002b86

points

almost 9 years

Answer 52cbff8980ff33dee3007d14

It’s interesting. I had the same problem, but I HAD a period at the end of sentence. Second advice: DO NOT COPY SENTENCE FROM THE INSTRUCTION! When I rewrote a sentence by hands, it passed.

points

over 8 years

What happens if you put a period at the end of a statement in Python?

The period makes it a floating-point number. So writing "640." is equivalent to "640.0". The period allows for natural division with python: if you are dividing two integers, the result is simply an integer (and fractional remainder is truncated).

What does a period mean in Python?

In python, a period accesses methods (functions) and properties (data) of objects.

How do you add a period to the end of a sentence in Python?

Alexander Davison. You can "add" (concatenate) the period character to the end of the string. For example: "Harpreet is learning Python" + "!" # This code returns "Harpreet is learning Python!"

How do you print a period at the end of a Python?

Put quotation marks around it. print first_name, "was born on", month, day+',', year +'. '

What does the period do in Python?

In python, a period accesses methods (functions) and properties (data) of objects. Parentheses are the only way to call functions, that I know of.

How do you add a period to the end of a sentence in Python?

Alexander Davison. You can "add" (concatenate) the period character to the end of the string. For example: "Harpreet is learning Python" + "!" # This code returns "Harpreet is learning Python!"

Can a python variable have a period?

With the exception of Cookie and Client scope variables, which must always be simple variable types, you cannot normally include periods in simple variable names.

How do you print a period at the end of a python?

Put quotation marks around it. print first_name, "was born on", month, day+',', year +'. '