TRENDING NEWS

POPULAR NEWS

Python Programming Questions Help Part 3

Programming question? (in python)?

I am taking a computer science class this semester and as part of our curriculum we must complete exercises from the book, "Python Programming: an Introduction to Computer Science" (2nd ed.), by John Zelle. So far I have completed all of the exercises with difficulty but am now stuck on number 7 from the programming exercises in chapter 2. I was wondering if anyone with any programming experience (or python experience) could help me at all. Here is the prompt for question 7:

7. As an alternative to APR, the interest accrued on an account is often described in terms of a nominal rate and the number of compounding periods. For example, if the interest rate is 3% and the interest is compounded quarterly, the account actually earns 3/4% interest every 3 months.
Modify the futval.py program to use this method of entering the interest rate. The program should prompt the user for yearly rate (rate) and the number of times that the interest is compounded each year (periods). To compute the value in ten years, the program will loop 10 * periods times and accrue rate/period interest on each iteration.

Thanks

I need help with python programming?

lol, homework much?

Anyways,

Question 1:

def square(h):
....'''Squares a number h and returns g'''
....g = h ** 2
....return g

>>> square(3)
9
>>> square(9)
81

Question 2:
Who wrote those instructions? I am not sure if I understand well the question but here is what i came up with:

def distance(step, stop):
....start = 1
....myList = []
....while start <= stop:
........myList.append(start)
........start += step
....return myList

>>> distance(3, 18)
[1, 4, 7, 10, 13, 16]
>>> distance(2, 18)
[1, 3, 5, 7, 9, 11, 13, 15, 17]

ps. I hope yahoo adds code tags :D
pss. fix the variable names. I hope your teacher taught you that?!
psss. damn, tabs didnt show up. You are a nice man, you can fix that ;)
pssss. each . is equal to a space :)

Python 3 programming question?

Which process? writing a function or calculating the longest side?

Here's a function that will print the square root:

def my_function(x):
... print( sqrt(x) )

Now let's call it:
print_sqrt(4)


Edit:
math.sqrt(a**2 + b**2) *is* the value you need.
Just print it.

Question about Python 3 dice rolling program.?

Hello worlds I am pretty new to Python and am a bit stumped on this one
:
Write a program to simulate the roll of two dice. Use a randomly generated integer to represent the roll of each die in a function named point. Return the combined value of a roll. Use a loop in main to roll the dice five times and report each result.

Here is what I have tried to do:

import random

def point():
print 'Rolling the dice. May the odds be ever in your favor'

dice_one = random.randint(1,7)

dice_two = random.randint(1,7)

total = dice_one + dice_two

print 'Your rolls are, total)


Here I dont really know how to loop this. If anyone could help I would be happy

HELP PYTHON 3 - Parsing strings Question?

I am trying to get the following to output. I am going to attach what I've attempted, but i'm getting a "EOFError: EOF when reading a line" for line 2 when I attempt to run my program.

MY CODE:
while(True):
inp_str = input('Enter input string:')

if (inp_str == 'q'):
break;

while(inp_str.find(',') == -1):
print('Error: no comma in string')
inp_str = input('Enter input string')

parts = inp_str.split(',')
first = parts[0].strip()
second = parts[1].strip()

print('First word:', first)
print('Second word:', second)
print('\n')

Help writing python programming code?

Okay, so which part are you having trouble with? What have you done so far?

They've told you how to get the input from the user. They've told you how to set up the while loop. Which of these are you having difficulty with?

Easiest way to program this in Python?

This is about as basic and short as it can get. Note: this assumes that eventually they will enter a repeated word. Also, no string interpolation.
This is a good way because effectively nothing is wasted. It does exactly what is asked for, with a thought process that's similar to our own. Keep on asking for more until a word is repeated. Then stop asking and say how many you entered.
This is also good because you store the values entered in a list. Really, you could just make a count instead.

list = []
word = raw_input("Start entering words:\n")
while word not in list:
list.append(word)
word = raw_input()
print "You already entered", word
print "You listed", len(list), "distinct words."

TRENDING NEWS