Qixi Festival is coming soon, use various programming languages to realize 10 ways of romantic confession


On this loving day of Qixi Festival, it is a very interesting idea to write some confession codes in programming languages. The following are 10 simple confession code examples written in various programming languages ​​such as Python, Java, JavaScript, and H5.
insert image description here

1. Direct confession:

def direct_confession():  
   print("亲爱的,我喜欢你,愿意和你共度余生。")  
   answer = input("你愿意和我一起走下去吗?(yes/no) ")  
   if answer.lower() == "yes":  
       print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
   else:  
       print("没关系,我会继续努力,争取赢得你的心。")
if __name__ == "__main__":  
   direct_confession()  

2. Confession on Qixi Festival:

def qixi_confession():  
   print("亲爱的,祝你七夕节快乐!")  
   print("在这个特殊的日子里,我想告诉你:我喜欢你,愿意和你共度余生。")  
   answer = input("你愿意和我一起走下去吗?(yes/no) ")  
   if answer.lower() == "yes":  
       print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
   else:  
       print("没关系,我会继续努力,争取赢得你的心。")
if __name__ == "__main__":  
   qixi_confession()  

3. Mind guessing game:

import random
def guess_heart():  
   print("我们来玩一个猜心游戏吧!")  
   print("我已经想好了一个字,猜猜是什么字?")  
   answer = input("请输入你猜测的字:")  
   while answer!= "爱":  
       answer = input("猜错了,请再试一次:")  
   print("恭喜你,猜对了!在这个特殊的日子里,我想告诉你:我喜欢你,愿意和你共度余生。")  
   answer = input("你愿意和我一起走下去吗?(yes/no) ")  
   if answer.lower() == "yes":  
       print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
   else:  
       print("没关系,我会继续努力,争取赢得你的心。")
if __name__ == "__main__":  
   guess_heart()  

4. Romantic lines:

def romantic_poetry():  
   print("亲爱的,我要为你写一首诗。")  
   print("在银河的两岸,")  
   print("有一对相望的星,")  
   print("那就是我和你。")  
   print("我喜欢你,愿意和你共度余生。")  
   answer = input("你愿意和我一起走下去吗?(yes/no) ")  
   if answer.lower() == "yes":  
       print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
   else:  
       print("没关系,我会继续努力,争取赢得你的心。")
if __name__ == "__main__":  
   romantic_poetry()  

5. The formula of love:

def love_equation():  
   print("亲爱的,你知道吗?")  
   print("我一直在寻找一个方程式,")  
   print("它可以表示我对你的喜欢,")  
   print("那就是:幸福 = 你 + 我")  
   print("我喜欢你,愿意和你共度余生。")  
   answer = input("你愿意和我一起走下去吗?(yes/no) ")  
   if answer.lower() == "yes":  
       print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
   else:  
       print("没关系,我会继续努力,争取赢得你的心。")
if __name__ == "__main__":  
   love_equation()  

6. Love Python:

import matplotlib.pyplot as plt  
import numpy as np
def main():  
  x = np.linspace(0, 2 * np.pi, 1000)  
  y1 = 16 * np.sin(x)**3  
  y2 = 13 * np.cos(x) - 5 * np.cos(2 * x) - 2 * np.cos(3 * x) - np.cos(4 * x)  
  plt.figure(figsize=(6, 6))  
  plt.plot(x, y1, color='red', linewidth=2)  
  plt.plot(x, y2, color='blue', linewidth=2)  
  plt.axis('equal')  
  plt.title("七夕节快乐!")  
  plt.show()
  print("愿我们的爱情如同牛郎织女般美好!")  
  print("你是我的宇宙中最亮的星,愿永远陪伴在你身边。")  
  input("按回车键继续...")
if __name__ == "__main__":  
  main()  

This code uses Python's Matplotlib library to draw a heart with the title "Happy Chinese Valentine's Day!".

7. Heart JavaScript code:

function drawHeart() {
    
      
  const canvas = document.createElement("canvas");  
  const ctx = canvas.getContext("2d");  
  canvas.width = 300;  
  canvas.height = 300;  
  ctx.beginPath();  
  ctx.moveTo(150, 180);  
  ctx.bezierCurveTo(150, 140, 110, 130, 75, 180);  
  ctx.bezierCurveTo(50, 250, 150, 250, 150, 180);  
  ctx.fillStyle = "red";  
  ctx.fill();  
  ctx.stroke();  
  document.body.appendChild(canvas);  
}
function main() {
    
      
  drawHeart();  
  console.log("愿我们的爱情如同牛郎织女般美好!");  
  console.log("你是我的宇宙中最亮的星,愿永远陪伴在你身边。");  
}
main();  

This code uses JavaScript to draw a heart shape and display it in the browser.

8. Heart-shaped and display confession message HTML page:

<!DOCTYPE html>  
<html lang="zh">  
<head>  
  <meta charset="UTF-8">  
  <title>七夕节表白</title>  
  <style>  
      body {
      
        
          font-family: Arial, sans-serif;  
          background-color: #f5f5f5;  
      }  
      canvas {
      
        
          display: block;  
          margin: 50px auto;  
      }  
  </style>  
</head>  
<body onload="main()">  
  <canvas id="heartCanvas" alt="心形图案"></canvas>  
  <script src="main.js"></script>  
</body>  
</html>  

This code creates an HTML page that contains a canvas element for drawing a heart shape. A JavaScript code snippet is also introduced to draw a heart and display a confession message.

9. Happy Tanabata in Java:

import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;
public class ValentinesDay extends JFrame {
    
      
  public static void main(String[] args) {
    
      
     ValentinesDay frame = new ValentinesDay();  
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
     frame.setSize(300, 300);  
     frame.setLocationRelativeTo(null);  
     frame.setTitle("七夕节快乐!");  
     frame.setResizable(false);  
     frame.setVisible(true);  
  }
  }
public class ValentinesDay extends JFrame implements ActionListener {
    
    
private JButton button;
private JLabel label;
public ValentinesDay() {
    
    
setLayout(new FlowLayout());
setTitle("七夕节快乐!");
setSize(300, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
}
private void createComponents() {
    
    
button = new JButton("点击发送祝福");
button.addActionListener(this);
label = new JLabel("请稍等...");
add(button);
add(label);
}
@Override
public void actionPerformed(ActionEvent e) {
    
    
if (e.getSource() == button) {
    
    
label.setText("祝福已发送!");
// 这里可以添加发送祝福的实际逻辑
}
}
public static void main(String[] args) {
    
    
ValentinesDay frame = new ValentinesDay();
frame.createComponents();
frame.setVisible(true);
}
}

10. Number plate of love:

import random
def love_number():  
   print("亲爱的,我们来玩一个游戏吧!")  
   print("我已经想了一个数字,你来猜猜看!")  
   number = random.randint(1, 100)  
   while True:  
       try:  
           guess = int(input("请输入你猜测的数字:"))  
       except ValueError:  
           print("请输入一个整数!")  
           continue  
       if guess < number:  
           print("猜小了!")  
       elif guess > number:  
           print("猜大了!")  
       else:  
           print("恭喜你,猜对了!")  
           print("我喜欢你,愿意和你共度余生。")  
           answer = input("你愿意和我一起走下去吗?(yes/no) ")  
           if answer.lower() == "yes":  
               print("太好了!我会珍惜我们之间的感情,一起走向未来。")  
           else:  
               print("没关系,我会继续努力,争取赢得你的心。")  
               break
if __name__ == "__main__":  
   love_number()  

In this code, the program randomly generates a number between 1 and 100, and then asks the user to guess. After the user guesses each time, the program will give prompts until the guess is correct. After guessing correctly, the program expresses love and asks the user if they want to walk down the road together.

Guess you like

Origin blog.csdn.net/superdangbo/article/details/132378516