Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Python to Java Partyguest

  1. #1
    scotty is offline Member
    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Default Python to Java Partyguest

    Hi I would like to converte that Python Code to Java Coud someone help me with a converting and a few comments:

    You are at a party with n people. One party guests start a rumor about another party guest.
    Every person who hears the rumor tells a it to another person and avoids to tell the person person from whom the speech is. If someone already knew the rumor, and this gets retold, this person does not spread the rumor further.
    The simulation should repeated and calculate 100,000 times and how many people on average learn the rumor.

    Thanks all so I have to change the guest to n people not 51


    import random
    guests = 51

    def simulation():
    Gaeste=[False for x in range(0,guests)]
    Gaeste[0]=True
    Sum = 0

    random.seed()

    while(True):
    listeners = random.randint(0,guests-1)
    if Gaeste[listeners]==False:
    Gaeste[Zuhoerer] = True
    else: break

    for x in range(guests-1):
    if Gaeste[x]:
    Sum += 1
    return Sum

    Summe = 0
    for x in range (100000):
    Summe+=simulation()
    average = Summe/100000

    print(average)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Python to Java Partyguest

    This is not a site where you ask others to convert code for you. Please feel free to try to code this yourself, and if you run into problems, ask a specific question and we'll be more than happy to help.
    DarrylBurke likes this.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default Re: Python to Java Partyguest

    Funny, Python lives or dies with (in)correct line indentation and the lack of code tags ruins the entire post ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Java vs. Python
    By bob 6 in forum Forum Lobby
    Replies: 3
    Last Post: 09-10-2012, 11:37 AM
  2. Passing arguments from java to python
    By wavefunction in forum Advanced Java
    Replies: 4
    Last Post: 07-10-2011, 04:36 PM
  3. Running a Python Script in Java
    By JavaN00bie in forum New To Java
    Replies: 6
    Last Post: 06-22-2011, 09:23 PM
  4. calling python file from java
    By cool in forum AWT / Swing
    Replies: 3
    Last Post: 11-11-2010, 03:50 AM
  5. Jython : python for java
    By cotarelo in forum New To Java
    Replies: 1
    Last Post: 03-25-2010, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •