Hello From Yilton Martinez

I am a new student of Python programming.

Hello, very good! Hope you can learn what you need from python.

Does anyone have any examples to display a python code stating “hello world”.

print( “hello world” )

Maybe consider the built in print function?

https://docs.python.org/3/library/functions.html#print

Cheers,
Cameron Simpson cs@cskk.id.au

Hi Yilton,

Googling for “python hello world” is pretty easy to do:

https://duckduckgo.com/?q=python+hello+world

If you don’t know how to google, you’re going to struggle to program.
There is a huge amount of tutorials, How To guides, help forums, source
code, etc.

https://duckduckgo.com/?q=python+tutorial

There’s tons of stuff about Python on the web, and knowing how to google
for it is important.

Thanks, Steven
Thanks for the tip. I do know how to use google pretty well. I just posted a simple question on this discussion to see if anyone on here has different ways to print that statement. But ofcourse i know how to use google, i think even my grandma knows hows to google. I’m just trying to use as many different sources of information as possible google is not always the most reliable place to get information some information on there is not always correct and can mislead you.

Hi Yilton,

You ought to fill us in with what you already know and what you are
looking for. If you don’t, we’ll probably think you are one of the many
beginners and newbies here who don’t always think of googling before
asking for help.

print("Hello world") is, of course, the most obvious way. But we can
also do:

import sys
sys.stdout.write("Hello world\n")

or if you want something even more obfuscated:

print(*map(chr, (0x48, 0x65, 0x6c, 0x6c, 0x6f, 
    0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64)), sep='')

And then there’s this:

try: 1/0
except Exception as e:
    (vars(e.__traceback__.tb_frame.f_globals[
    ''.join(chr(ord(c)-81) for c in '°°³Æº½Åº¿Ä°°')])
    [''.join(chr(ord(c)-62) for c in '®°§¬²')](
    *map(chr, (0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,0x6c,0x64)
    ), sep=''))

You are not supposed to understand that. I wrote it and I barely
understand it wink

Enjoy!

Does anyone know how to prompt a user in kilometers and calculates a light year and displays the result? The information i have for the calculation is 90 degrees containing 60 minutes of arc and also a kilometer is 1/10,000 the distance from the north pole to the equator.

A light-year is its own unit of distance, defined as the span light
travels through a vacuum over the course of one terrestrial year,
roughly ten trillion kilometers. I think you’re wanting to calculate
something else, based on your description, but may have chosen the
wrong words?

Hi Yilton,

“90 degrees containing 60 minutes of arc” is a nonsense sentence. It is
literally true, in that 60 minutes of arc is smaller than 90 degrees,
like an inch is smaller than a mile. But 90 degrees has nothing to do
with a lightyear, or a kilometre. It is an angle, not a distance.

The distance from the north pole to the equator is 9944.35 km, not
10000.

If you google for “lightyear” you will find out exactly how many
kilometres are in a lightyear. Then write a program to prompt the user
for some kilometres, and do your conversion. You can start with the
Python function input:

distance = input("How many inches? ")
distance = float(distance)
print(f"You asked for {distance} inches.")
converted = distance/12
print(f"That is {converted} feet.")

If you have trouble, show us the code you have written. Don’t take a
photo of it, or a screen shot. Copy and paste the code into your
message. Don’t forget to format it as code: if you use the GUI editor,
there’s a button that formats it as code.

This is the question from the book. I actually meant nautical miles, not light-years lol.

Write a program that takes as input a number of kilometers and prints the corresponding number of nautical miles.

Use the following approximations:

  • A kilometer represents 1/10,000 of the distance between the North Pole and the equator.
  • There are 90 degrees, containing 60 minutes of arc each, between the North Pole and the equator.
  • A nautical mile is 1 minute of an arc.

I meant nautical miles. The program should request input for Kilometers and output nautical miles

Ah, well do it on paper first.

Approximation 1 means you can pretend there are 10000 kilometers from
the north pole to the equator.

How many minutes of arc are there in that arc, according to
approximation 1 (which isn’t approximate).

Divide one by the other, since a nautical mile is 1 minute of arc.

Write those down as equations on paper. Solve.

Write the same equations into a Python programme, add an input() call to
get a value for kilometers, apply the equations to compute nautical
miles. print() the result.

If you get stuck, come back here with what you have accomplished and
what’s going wrong.

Cheers,
Cameron Simpson cs@cskk.id.au

This is where I am. I inputted 100 and the answer was supposed to be 54 nautical miles but instead, I’m getting 150
#declare variables and constants

minutes = 60

degrees = 90

#prompt user

kilometer = int(input("Enter the number of kilometers: "))

#calculate nautical miles

arc = minutes / degrees

nautical = kilometer / arc

#display number of nautical miles

print("The number of nautical miles is " + str(nautical))

Assorted remarks:

These are just variable assignments (aka bindings). There pretty much
are not “declarations” in Python.

#declare variables and constants
minutes = 60
degrees = 90

Longer names will make these easier to use and understand. “minutes per
degree” and “degrees_per_arc” might be clearer.

#prompt user
kilometer = int(input("Enter the number of kilometers: "))

#calculate nautical miles
arc = minutes / degrees

This does not make sense. There are 60 minutes in a degree, and 90
degrees in the arc. So should this not be a multiplication? Giving
(again for a longer name) minutes_per_arc.

You’re missing a constant for kilometers_per_arc = 10000.

nautical =  kilometer / arc

If you have minutes_per_arc and kilometers_per_arc, and a nautical mile
is 1 minute of arc, then you should now compute the ratio between
kilometers and minutes as a distinct variable eg kilometers_per_minute
or minutes_per_kilometer.

Print it out. As a rough sanity check, a nautical mile is a little like
a land mile (they are not equal, though), and a land mile is 1.609344
kilometers. So your ratio should be in this ballpark. Or its
reciprocal.

Then multiply (or divide, depend on which ratio you compute above)
“kilometer” by that ratio.

nautical = kilometer * the_ratio_from_above

#display number of nautical miles
print("The number of nautical miles is " + str(nautical))

print() will do str for you. So you could write:

print("The number of nautical miles is", nautical)

for less complication.

Cheers,
Cameron Simpson cs@cskk.id.au

Awsome Cameron. Thanks for the help, I got the program to run correctly with the correct calculations.
#declare variables and constants

minutes = 60

degrees = 90

#prompt user

kilometer = int(input("Enter the number of kilometers: "))

#calculate natical miles

arc = degrees * minutes

nautical = kilometer /10000 * arc

#display number of nautical miles

print("The number of nautical miles is ", nautical)

Im having a hard time making a table with this information. Does anyone have any tips on finishing this code. Below is my current code.

The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of 12%. Monthly payments are 5% of the listed purchase price, minus the down payment. Write a program that takes the purchase price as input. The program should display a table, with appropriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items:

the month number (beginning with 1)

the current total balance owed

the interest owed for that month

the amount of principal owed for that month

the payment for that month

the balance remaining after payment

The amount of interest for a month is equal to balance * rate / 12. The amount of principal for a month is equal to the monthly payment minus the interest owed.
#declare variables
downPaymentRate = 10
monthlyPaymentRate = 5
anaulInterest = 12
month = 0
#Prompt user
purchasePrice = float(input("Enter purchase price: "))
#convert down payment rate to decimal
downPaymentRate = downPaymentRate / 100
monthlyPaymentRate = monthlyPaymentRate / 100
anaulInterest = anaulInterest / 100

#display the table header
print("%5s%16s%14s%15s%16s%26s" %
(“Month”, “Current balance”,
“Interest owed”, “Principal owed”, “Monthly payment”,
“Balance due after payment”))

#compute and display results for each month
for month in range(1, months + 1):
currentBalance = downPaymentRate * purchasePrice
interestOwed = currentBalance * anaulInterest
principalOwed = currentBalance
monthlyPayment = currentBalance + interestOwed
endingBalnace = currentBalance - monthlyPayment
print("%5d%16.2f%14.2f%15.2f%16.2f%26.2f" %
(month, CurrenBalance,
interestOwed, principalOwed, monthlyPayment,
endingBalance))

Hello Everybody, I too msignature1