Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output to programs
#1
What is the value of h(231,8) for the function below?
  def h(m,n):
    ans = 0
    while (m >= n):
      (ans,m) = (ans+1,m-n) 
    return(ans)
2.Consider the following function h.
  def h(n):
    f = 0
    for i in range(1,n+1):
      if n%i == 0:
        f = f + 1
    return(f%2 == 1)
The function h(n) given above returns True for a positive number n whenever:

n is a multiple of 2
n is a composite number
n is a prime number
n is a perfect square


[b]what would be the output of the following two programs in python?[/b]
Reply
#2
1. Please put the code in Python code tags. You can find help here.
2. You will need to find the answer to questions yourself. We can help by explaining what specific lines of code do, but for that, ask specific questions.

Anyway... what prevents you from running the code and getting the results?
Reply
#3
I just copied the code and pasted it in the interpreter but it does not show any results.after the return(m) statement i don't know what to do.Please provide guidance how the code will execute.
Reply
#4
I don't see any return(m) in the code you posted. Please post exact code you tried to run.

Other thing is, the two function blocks in the original post are just function definitions, not executions of those functions.
If you are not familiar with basics of functions, I suggest checking one of the numerous tutorials freely available online. You can start with one on our forums.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020