How to Code a Relationship Calculator

Start with a random function., Construct a way of getting the names., Sort the names so that it doesn't matter what order you put the names in., Set the seed random.seed()., Get the random number random.random() and multiply by a hundred and round...

6 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Start with a random function.

    Most program languages require import.

    In python it's import random. , It can be a file, a user input or a PHP post/get.

    This example is just going to use Python
    2.7's raw_input(); if you are on Python, 3 use input().

    The names should also be in lowercase, and there should be two of them.

    The next lines are name1=raw_input('Name1:').lower() and name2=raw_input('Name2:').lower() , To do that we place the names in a list, , and sort it with .sort().

    You need to save the list as well so the full line is names=.sort() , It will be the to names merged "".join(names).

    So the next line should be random.seed("".join(names)). , The full line is love=str(round(random.random()*100)). , It should be something like print(love+"%").
  2. Step 2: Construct a way of getting the names.

  3. Step 3: Sort the names so that it doesn't matter what order you put the names in.

  4. Step 4: Set the seed random.seed().

  5. Step 5: Get the random number random.random() and multiply by a hundred and round it and make it a str so you get percent.

  6. Step 6: Print your answer.

Detailed Guide

Most program languages require import.

In python it's import random. , It can be a file, a user input or a PHP post/get.

This example is just going to use Python
2.7's raw_input(); if you are on Python, 3 use input().

The names should also be in lowercase, and there should be two of them.

The next lines are name1=raw_input('Name1:').lower() and name2=raw_input('Name2:').lower() , To do that we place the names in a list, , and sort it with .sort().

You need to save the list as well so the full line is names=.sort() , It will be the to names merged "".join(names).

So the next line should be random.seed("".join(names)). , The full line is love=str(round(random.random()*100)). , It should be something like print(love+"%").

About the Author

L

Lori Cox

Lori Cox has dedicated 9 years to mastering lifestyle and practical guides. As a content creator, Lori focuses on providing actionable tips and step-by-step guides.

44 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: